The assignment asks for me to loop until I get to “Notorious B.I.G.” then break… Why can’t I do this by setting i === 2; it prints out fine… Wouldn’t this work?
can you provide the exercise url and copy paste the code onto the forum? Working from a screenshot is very difficult
seems Notorious B.I.G still need to be logged, so the break should be after console.log
The hint gives the following:
myArray[myArrayIndex] === 'element value';
i would go for that solution, it means you can the elements in the array without breaking the behavior of your code
Yes, but my solution printed correctly to the console. I guess that’s my question… Is mine correct? I did it their way just so I could get through the exercise.
The third element (index 2), still needs to be logged. Your code doesn’t do this.
i don’t like screenshots, can you copy the code to the forum? Then i can actually run the code, that debugs like a million time more easily
const rapperArray = ["Lil' Kim", "Jay-Z", "Notorious B.I.G.", "Tupac"];
// Write you code below
for (let i = 0; i < rapperArray.length; i++){
console.log(rapperArray[i]);
if (i === 2){
break;
}
}
console.log("And if you don't know, now you know.");
Works fine for me? Do you get any errors? Make sure to complete step one before inserting the break
anyway, there is nothing wrong with your code, that is the essential point
ha thanks for going through it with me; that’s the only bad thing about codeAcademy sometimes you have to do it exactly the way the exercise wants!
Thanks again!
i can complete the exercise with your code, so it does work.
Hello, @bhb23955.
Your code produces the correct results only beacause you know the index of the element you are wanting to print. What if you had an array of hundreds of elements, and wanted to print a specific value, but didn’t know where in the array it was?
Yes,
I thought of that, but for a small, finite array it isn’t wrong technically.