Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Error in JavaScript level 5 lesson 5

let x = 0;

while (x < 10) {
if (x == 5) {
console.log(x);
break;
}
x++;
}

I get an error saying "define the if with a break statement inside it". Can someone please help me with this error?
by

2 Answers

iamabhishek
You are pretty close to the correct solution. Try this:

let x = 0;

while(x < 10){
console.log(x);
if(x === 5){
break;
}
x++;
}
kshitijrana14
Try this one

let x = 0;

while(x < 10){
console.log(x);
if(x === 5){
break;
}
x++;
}

Login / Signup to Answer the Question.