What's wrong with this code?


#1

I put this code in for review in Introduction to 'While' Loops in JS and it says illegal in the console, that is wrong? I know it's not the most efficient way to do the counting but whats wrong with it? thanks in advance!

//variables for loops
var count = 0
var count2 = 0
var count3 = 0
var saftey = false

//loops
for(count; count < 5; count++)
{
console.log("Your for loop worked!);
}

while(count2 < 5)
{
    console.log("Your while loop worked!");
    count2++;
}

do
{
console.log("Your do statement worked on the first part!");
count++;
}
while(count3 < 5)
{
console.log("The second half for your do statement worked too! great job!");
count3++;
}


#2

do
{
 console.log("Your do statement worked on the first part!");
 count++;
}
while(count3 < 5)

Nothing after this line is being counted because you did a "do - while loop" so it'll run everything between the do, and the while. but not after the while.


#3

Hi @magiccookie

  • You forgot " (line 9)
  • "count++" must be replace to "count3++" (line 23)
  • You have to delete line 27 to line 30

Hold on :wink:


#4

thanks so much! such little errors lol


#5

thanks so much as well! that makes much more sense for how do statements work than what i was thinking