Kingston_Pendrive/Suli/13.b/Frontend/Javascript/2024. 09. 09/js/IntervallumFeladat.js
2024-11-19 19:04:02 +01:00

24 lines
538 B
JavaScript

let number1 = Number(prompt("Add meg az intervallum elejét:"))
let number2 = Number(prompt("Add meg az intervallum végét:"))
let listaSzamok = []
if (number1 < number2) {
for (; number1 <= number2; number1++) {
listaSzamok.push(number1)
}
} else {
for (; number1 >= number2; number1--) {
listaSzamok.push(number1)
}
}
console.log(listaSzamok);
let sum = listaSzamok.reduce((accumulator, currentValue) => {
return accumulator + currentValue
})
console.log(sum);
console.log(listaSzamok.length);