Kingston_Pendrive/Suli/13.b/Frontend/Javascript/2024. 09. 09/js/IntervallumFeladat.js

24 lines
538 B
JavaScript
Raw Permalink Normal View History

2024-11-19 18:04:02 +00:00
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);