Iterate with JavaScript Do...While Loops (Possible Solution Here)

Tell us what’s happening:
Hi campers!

Just wanted to point out some issues with a lesson I am on:

  1. I’m getting a 404 error while clicking the hint button for the “Iterate with Javascript Do…While Loops” Basic Javascript lesson.

  2. Please find my solution below. My question is: is there a problem with using the .splice(i-10) code to create the solution? Happy for this to be used as a solution if there aren’t any issues from the more experienced community.

Thanks for your time.

Your code so far


// Setup
var myArray = [];
var i = 0;

// Only change code below this line.

do {
  myArray.push(i);
  
  i++;

  myArray.splice(i-10);
}

while (i < 11);


console.log(myArray);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0.

Link to the challenge:
Can’t link yet. Not allowed.

Can you explain your logic in using that? What it is you want to do, what do you think it is doing…

The only thing you need to do is change the loop to a do…while, anything else is just extra resources taken for nothing.
You don’t need to change the initial var i = 10 or the comparison. Because even if i < 5 is false the do … while loop still execute once

It’s not exactly a problem, but don’t you think it would be more efficient, if you’d just initiate i with value of -10? It would save you 11 substraction operations at least :slight_smile:

This challenge just asks you to convert the while loop to a do while loop. The logic inside it is irrelevant.

I think I had better learn more about coding and javascript before I post again. Thanks though!

better ask dumb questions here than those a*****s on stack-overflow

Dumb questions are those that are not asked!

(Resources is a thing you need to consider, later on if your solution is not optimised a bit you can’t pass the tests because they time out)