Javascript lesson crashes when running test

In the Introduction to Javascript series, I am stuck in the following lesson:

Iterate with JavaScript Do While Loops

After updating my code and selecting “Run The Tests”, the page freezes. I had previously completed this lesson a few days ago and wanted to review the material. This is the only lesson that has frozen for me thus far. Any ideas?

The dev console states “// running tests”

I added one line of code: i++;
and it stopped locking up when running the tests. Now it gives the following error codes:

myArray should equal [10].
i should equal 11

I added console.log statements to find the value of the array and I and they both matched the required values. No clue why it still errors out Code from the editor pasted below.

// Setup
var myArray = [];
var i = 10;
// Only change code below this line.
do {
while (i < 5) {

The do-while executes at least once if the condition set in the while is not evaluated to true however, the while statement doesn’t carry a block of code as you have written it above.
Use this instead


since you initial value of i is set to 10, the code above will only add one element into your array.
Two things to note with the do-while
1)All the actions you want carried out should be in the do block
2)The while statment doesnt carry a block of code.

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


Also, you should definitely indent your code (2-4) spaces, to make it easier for others to read your code in general.

1 Like

Thank you for the assistance. That was my initial post in this forum and I was not aware of formatting expectations. This will assist me in future posts.

Also, I now understand the logic of the do while loop. Thanks to both of you.