What am I missing? exercise 9.9.1

let incrememntedNumbers = [];
let oddNumbers = [];
let evenNumbers = [];
let descNumbers = [];

for (let i = 1; i < 51; i++) {
if (i<21){
incrememntedNumbers.push(i);
}
else if (i % 2 != 0){
oddNumbers.push(i);
}else if (i % 2 == 0){
evenNumbers.push(i);
}else if (i > 19){
descNumbers.push(i);
}
}
descNumbers = descNumbers.reverse();
console.log('number count: ',incrememntedNumbers);
console.log('odd numbers: ',oddNumbers);
console.log('even numbers: ',evenNumbers);
console.log('descending numbers: ',descNumbers);

The output is returning number count correctly but odd numbers not appearing until 21, and even at 21, and descending numbers not appearing.

Thanks

It seems you need several for loops and if statements. If/else stop executing the code once the condition reads to true. If you hit a truthy condition you won’t be able to fill your arrays with the numbers necessary so it doesn’t read it. I’d suggest 1 for loop for your odd/even numbers then another for your ++/-- numbers. I hope this helps!

1 Like