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?
4 odpowiedzi
+ 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)
+ 2
Thanks! You've been very helpful!
+ 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.
+ 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.