Just a minor explantion JS [spoiler] NEW

var i=10
do {
  myArray.push(i)
  i++
  } while (i<5)

console.log(i, myArray)

So, within this code, I just have one simple question. When I do
console.log(i, myArray), I get two things in my console: the numbers 11, and 10. I understand where the 11 came from, as it is i incremented (occurs because of the do statement, which runs the code first, and checks later if it fits the parameter), but however, where does the 10 appear from?

Hello there,

If you are referring to this output:

11 [10]

It is because you are logging myArray to the console, as well. You push i (when it is equal to 10) to the array, then log it to the console.

I hope this helps

sorry, there was a line missing at the top: myArray=[]. So what you’re saying is that the array is just i, but why?

Well, your do...while condition is i < 5. However, you already start with i > 5 so the itteration will only run once. Therefore, this line only gets executed once:

myArray.push(10)

So, console.log(i, myArray) logs both i (equal to 11), and myArray ( consisting of [10]).

Perhaps, to help you understand, replace your first line
let myArray = [] with let myArray = [5];

Hope this helps

1 Like

So, it pushes 10 into the array, put doesn’t increase it. OHHHHHHH.