0

I am a newbie trying to understand the basics of Javascript with some basic exercises but I can't do this one. Any idea of how should I write it instead?

var array5 = [1,2,3,4,5];

for (var i=0; i<array5.length; i++) {
console.log(array5[i]);
  if (array5===[2]) {
  alert("we are in the middle of loop");}
}

PD: by the way, it has to be using the for loop and conditional if.

Thanks!

Pepdbm 7
  • 189
  • 3
  • 9
  • 3
    `if (i == Math.floor(array5.length/2)) {` – Taki May 07 '18 at 16:01
  • 1
    You're using `=` inside an if, you want a comparison `===` not an assignment – Sterling Archer May 07 '18 at 16:02
  • 1
    While this is certainly a duplicate, I don't see how this question duplicates the one chosen. If anything, it would just confuse a beginner. –  May 07 '18 at 16:18
  • Sterling Archer, I still don't get the output when writing it as you said:var array5 = [1,2,3,4,5]; for (var i=0; i – Pepdbm 7 May 07 '18 at 17:53
  • @Sterling Archer I don't see neither this is a duplicate of the one you proposed really... could you please answer it instead referring it to another issue. As I said it still doesn't work with the === you said before. Thanks – Pepdbm 7 May 07 '18 at 18:20

0 Answers0