Code is correct though not passing test Break Keywords Javascript

I’m working with the break keywords for javascript and the task is to Log each element from rapperArray in a for loop with the iterator variable i .
So here is my code, but codeacademy says it’s wrong. How is this incorrect?

const rapperArray = [“Lil’ Kim”, “Jay-Z”, “Notorious B.I.G.”, “Tupac”];

// Write your code below

for (let i = 0; i <= 3; i++){
console.log(rapperArray[i]);
if (rapperArray[i] === “Tupac”)
break;
}

Hello @savagelm, welcome to the forums! Could you post a link to the exercise, please? Is the code throwing an error?
You should have an opening { here:

and therefore a closing } at the end of the code inside the if block.

1 Like

Sure, but I do have a { and a closing }

Link is: https://www.codecademy.com/courses/introduction-to-javascript/lessons/loops/exercises/break-keyword

I meant for the if block. Are you following all of the instructions given?

Ahh, I got it, I think I was supposed to use the rapperArray.length and not <= 3

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.