8/12 Not printing my names?


#1

var names = ["Kelly" , "Korin" , "Courtney" , "Regan" , "Riley"];

for (var i = 0; i < names.length; i++) {
console.log("I know someone called "+ [i])
}

It prints as:
I know someone called 0
I know someone called 1
I know someone called 2
I know someone called 3
I know someone called 4

with an error message reading:
"Oops, try again. Your code should have printed 'I know someone called Kelly', but didn't."


#2

Hi @shaekelly

If it may help please see the code example below. In short you have the right idea but you're just missing one minor piece, in order to be able to print the names you need to call said names (reference the array, and its index to get its value), so just go ahead and alter your expression for [i] to actually call the value of the array with names[i] and you should be good to go.

var names = ["Kelly" , "Korin" , "Courtney" , "Regan" , "Riley"];

for (var i = 0; i < names.length; i++) {
console.log("I know someone called "+ names[i]); //add the array reference so you call that index with i
}

#3

@mike_in_training

Oops, try again. Your code should have printed 'I know someone called Kelly', but didn't. Make sure to type the 'I know someone called ' part exactly right, and don't forget the space between that phrase and the name!

Now it's printing out the names correctly, but the error (above) is still popping up?!


#4

@shaekelly, if I run the updated version of your code, that is posted in my original post the lesson accepts the output and marks it as successful ready to move on. To test this yourself please try to highlight all the text in the coding area; place cursor in coding area, press CTRL + A to select all, then press delete. Once the area is blank please try copying and pasting only the updated code and try to save an submit, you should then hopefully be able to pass the lesson and carry on.
If this fails for any reason please take a screen shot of your coding area with the code and error displayed and someone will try to help you as soon as they can.