What is wrong with my code?


#1

what is wrong with my code??
// Edit this for loop!

for (var i = 100; i < 0; i -= 5) {
console.log(i);
for (var i = 100; i > 0; i -=5) {
console.log(i);


Browser (safari and chrome) hangs(has been 2 days now) when clicked on "save&submit", lesson-introduction to 'for' LOOPS in JS, 5th topic
#2

The loop will only run if the conditional is true. i cannot be equal to 100 AND be less than 0 at the same time. The loop never runs. These two lines may be removed.

Note the closing curly brace added below. Code blocks need { and } as delimiters.

for (var i = 100; i > 0; i -=5) {
    console.log(i);
}

Notice in the above that i can be equal to 100 AND be greater than 0 at the same time, so the condition is true and loop executes. It should print out,

100
95
90
...
15
10
5

#3

it didn't printed out the numbers; instead, it returns with syntax error. my code is

for (var i = 100; i > 0; i -= 5;) {
console.log(i);
}


#4

You added an error by writing the semi-colon after the 5.


#5

oopsies. my bad. thanks for the help.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.