JavaScript Odd Number Output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

JavaScript Odd Number Output

Why does it output multiples of three instead of odd numbers? https://code.sololearn.com/WIAnwKTSfCJZ/?ref=app

13th Mar 2022, 4:52 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
5 Answers
+ 3
Your code is incrementing i twice. Take another look at it, especially the for loop.
13th Mar 2022, 5:10 AM
ODLNT
ODLNT - avatar
+ 3
Thank you, ODLNT and Adil and SoloProg . This is such a simple thing but for some reason, I thought you have to use the incrementer (++). Thanks for the help!
13th Mar 2022, 2:12 PM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
+ 2
In line 1 you add 1 every time the loop starts and in line 2 you add 2 every time the loop runs. So, 1 + 2 = 3 (that's why it shows multiples of 3). You should only add once, instead of i++ (incrementing th value) you should add 2 to i. Happy coding šŸ¤ 
13th Mar 2022, 6:16 AM
Adil
Adil - avatar
+ 2
// To Improve Your Code for(let i=1; i<20; i+=2) console.log(i);
13th Mar 2022, 8:51 AM
SoloProg
SoloProg - avatar
+ 2
Happy to help šŸ¤ 
13th Mar 2022, 2:16 PM
Adil
Adil - avatar