7 Practice Counting Down

I truly baffeld, I wrote this code here:

for (var i = 10; i >= 0; i–)
{
console.log(i);
};

I thought it would:

-define the variable as 10

  • it would see the variable is greater or equal to 0
    -it would subtract 1
    -it would print the variable

Where have I gone wrong in my logic?

4 Likes

for(var i = 10; i >= 0; i–) {

I do not see any problems with your code, the only difference I see between my answer and yours is that your start statement “{” and is on a different line, that may be the issue but I am not sure, please try this and reply to me if it works or not.

2 Likes

As @claradavies said it doesn’t look that wrong. Did you try to refresh the page? And what is the error message you’re getting?

2 Likes

SyntaxError: Unexpected token for

That’s it, I’ll try refreshing and seeing what happens. Maybe I’ll contact codecademy :stuck_out_tongue:

1 Like

Didn’t work out. :confused:
contacting codecademy about it

1 Like

I know what is wrong. This is what you are doing:
for(var i = 10; i >= 0; i–) {
You are not supposed to have VAR inside the loop. It should look like this:
for(I = 10; i>=0; i–) {
(code block)
}

3 Likes

The var is actually correct here also your second approach doesn’t make much sense as you’re using a I to start at 10 but using small i in the process.

1 Like

Hey @tagwhiz35336, I was having the same trouble you were. I don’t think your code is wrong, I just don’t think it’s exactly what Codecademy wanted. After re-reading the hint, I tried setting the condition to “i > -1” and that worked for me. Hope that helps!

3 Likes

It is correct just move the } up a line

2 Likes

This worked fine for me. Try using Chrome and refreshing, that “fix” usually works for me.

1 Like