I have a problem in the lesson "The Break Keyword" where i think instructions are not clear

Log each element from rapperArray in a for loop with the iterator variable i .
This is what I have been told in the first step. But after I wrote the code …it says *Did you create a for loop that loops through rapperArray?
I wrote the following code -

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

// Write your code below
for(i=0;i < rapperArray.length;i++){

1 Like

From what I can see, your only real error is your quotation marks. When I copy and paste your code into my editor, your strings in your array are red which means that they are not recognised as strings. This could just be a copy/paste error on my side or your side but make sure that your strings are yellow. You can use ` ’ or ". Feel free to copy/paste to see the difference.

Seconly but not essential, it’s good practice to use let when declaring i inside your for loop. Var, const and let do different things. Since we’re changing it’s value, we should use let. I’ll include a little link so you can do some research if you please :slight_smile:
Your code will still work without let, const or var but if you don’t use keywords (let, var and const) then when you look back at the code later, you won’t know if that variable has been declared before and will end up spending ages looking for where you declared that variable in your code when in reality, that was the first time it was ever mentioned.

So in short, for practicality and readability, it’s good to use keywords. The reason you’d know that let i = 0 is the first time i appears is because you cannot declare a variable with the same name twice. Hopefully this makes some sense. If it doesn’t, don’t hesitate to ask. I can rephrase it in another way for you.

Here’s a link on the differences between let, const and var : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements

If you want to test the correct code, copy and paste this and see the differences.

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

// Write your code below
for(let i=0 ; i < rapperArray.length ; i++){

*P.S. When posting code in the forums, you can press </> on the top and paste your code between the backticks to put it in the code format fo the forum. It just helps with readability :slight_smile: *

Have a nice day :smiley:


Thank you …i will run the code that you provided

1 Like

i see its just that let that was bothering me …lol thanks for your valuable time man

1 Like

Np. Happy it helped.