Error it no worky wy?

Tell us what’s happening:
SyntaxError: unknown: ‘return’ outside of function (5:0)
why???

Your code so far


// Setup
var myArray = [];
var i = 5;
while (i < 0);
return i --;
// Only change code below this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Iterate with JavaScript While Loops

Link to the challenge:

Your loop will do nothing as you’ve closed it without any instruction…

return statement only works within function, read about it here

You’ve been creating a lot of posts about syntax errors. I think you need to go slower and read carefully.

In the code you shared, it says “Only change code below this line” but you have ignored that. The syntax error is also telling you what is wrong: you have a return that is not inside a function.

Trying to go fast is just going to make you completely lost. Programming is a skill built on careful attention to detail.

2 Likes