0

Who can help me?

for (i=20; i == 6; i+=20) { console.log(i + 20); } This code should output the following sequence: 20 40 60 80 100 120 But the code outputs the wrong thing. I looked at the lessons, like everything should be like this, but nevertheless, an error crept in somewhere. Who can tell me where this error is?

13th Dec 2020, 7:30 AM
John List
4 Respostas
+ 2
use `let` when declaring variables: let i =20; otherwise it'll fail in strict mode. Your condition is wrong. It should be i<=120 not i==6 then print only i : console.log(i)
13th Dec 2020, 7:35 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Thanks! You've been very helpful!
13th Dec 2020, 7:38 AM
John List
+ 2
You are doing something wrong. You can do something like for(let i=20; i<=120; i+=20) console.log(i); Just check lessons again and Remember the different conditions used in loops. Tips Declare variable The second condition in for loop will be the termination condition. And finally third will increment or decrement.
13th Dec 2020, 7:39 AM
Kuber Acharya
Kuber Acharya - avatar
+ 1
Thank you for your help. For some reason, the topic of cycles caused me the greatest difficulties, so sometimes I have to ask for help.
13th Dec 2020, 7:41 AM
John List