[Bug Reported] Solution code not advancing lesson

So can anyone explain why this code will not complete the tasks?

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.”);

1 Like

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 :slight_smile:

// 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

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

// 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.”);*/

5 Likes

Thanks! you’re example got me through it.

const rapperArray = ["Lil' Kim", "Jay-Z", "Notorious B.I.G.", "Tupac"];

// 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.");

for whatever reason it didn’t like having the:

console.log(rapperArray[rapperArrayIndex]);

below the if statement despite that’s how it’s shown in the example. Once I moved it above it worked.

3 Likes

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.

2 Likes

quick question…why do we need to console log rapperArray[I] before If statement? How does that affect the functionality?

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

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.”);

Why won’t this work? I’m only on step 1. This should work.

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

// Write your code below
for (i = 0; i < rapperArray.length; i++ ){
console.log(rapperArray[i]);
}

OUTPUT: LIL KIM, JAY Z, NOTORIOUS B.I.G., TUPAC

This lesson is all over the place. The directions aren’t clear. What works and what doesn’t is mixed up.

I struggled with this as well.

They want you to

let = i

so it would be

for (let i = 0; i < rapperArray.length; i++ ){
console.log(rapperArray[i]);
}

1 Like

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.

Hope that makes sense :slight_smile:

1 Like

it is working correctly. But i think the codecademy program wants you to assign the i variable a little differently. By using let i = 0;

so it should look like this to pass their editor --> for (let i = 0; i < rapperArray.length; i++)

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.”);

it’s work!

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])
};

Yep, this fixed it for me!!!

Never too late!!! :grinning: