// Write you code below
for (let i = 0; i < rapperArray.length; i++) {
console.log(rapperArray[i]);
if (rapperArray[i] === “Notorious B.I.G.”) {
break;
}
}
console.log(“And if you don’t know, now you know.”);
There seems to be some issue with this exercise. I was pulling my hair out and questioning everything so had just to get the solution to see what I was doing wrong but it would seem I was doing nothing wrong? I restarted the exercise (not before I copied and pasted the solution to compare) and recoded again and did the same as the solution just not using i naming convention and even when I did it was still incorrect?
I also used the exact copied and pasted solution provided and it did not resolve the exercise so I have reported a bug.
This is just for others like me, you ain’t going mad I promise
// code per instructions (relevant variable names etc)
// compared to the solution copied and pasted below (before restarted this exercise) is the same code just relevant variable names etc which has caused much confusion
// Write you code below
for(let rapperArrayIndex = 0; rapperArrayIndex < rapperArray.length; rapperArrayIndex++) {
console.log(rapperArray[rapperArrayIndex]);
if (rapperArray[rapperArrayIndex] === ‘Notorious B.I.G.’){
break;
}
}
console.log(“And if you don’t know, now you know.”);
// correction solution copied and pasted before reset exercise.
/*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 (rapperArray[i] === ‘Notorious B.I.G.’){
break;
}
}
console.log(“And if you don’t know, now you know.”);*/
I have also experienced this inconsistency between the lesson and the instructions. The only difference between the solution code and my code was the placement of console.log(rapperArray[i]);, which contradicts the lesson.
for (let i = 0; i < rapperArray.length; i++){
console.log(rapperArray[i]);
if (rapperArray[i] === ‘Notorious B.I.G.’){
break;
}
}
console.log(“And if you don’t know, now you know.”);
Don’t know if this is a little to late for an answer.
But here is what i found.
When you add the if-statement before the console.log, then the string ‘Notorious B.I.G.’ is not included in the answer, so you are left with just ‘Lil KIm’, ‘Jay-Z’ and “And if you don’t know, now you know.”
so by console.log the elements from the array before the if-statement, the 3 elements are logged before the loop is broken.
for(let i=0; i < rapperArray.length; i++){
console.log(rapperArray[i])
if(rapperArray[i] === ‘Notorious B.I.G.’){
break;
}
}
console.log(“And if you don’t know, now you know.”);
The computer is saying that the code below does not create a for loop that logs through rapperArray (step 1), even though that is what my code is doing.
for (i = 0; i < rapperArray.length; i++){
console.log(rapperArray[i])
};