Loops and Arrays II


#1

var names = ["John", "Mark", "Teresa", "Annabel", "Andrea"];
for (var i = 0; i < names.length; i++) {

console.log("I know someone called " + "" + names[i]);

}


Replace this line with your code.


#2

You need a space between the quotes to have the sentences formatted correctly on the screen


#3

Hi I changed it and it still didn't work !
I have redone the code to this ;

var names =["john","michael","teresa","annabel","andrea"];
for (var i=0; i< names.length; i ++){

console.log=("I know someone called " + names[i])

}
it does print but only one line for andrea and with an error message

Oops, try again. Your code should have printed 'I know someone called john', 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!


#4

So your first one was closer to being correct. The only change you need to make is you need to put a space between the "" in between the + and +


#5

I removed the "=" from console.log


#6

This is the code I tried
var names = ["John", "Mark", "Teresa", "Annabel", "Andrea"];
for (var i = 0; i < names.length; i++) {

console.log("I know someone called " + " " + names[i]);

}
I am now getting the error code ;
TypeError: Function expected


#7

After called you have a space. Remove it.


#8

I have removed the space and I am still getting the same error message . I only have a couple of days to go through this course and its giving me a hard time . This is very frustrating !


#9

Try to refresh page and after that pass the lesson. Your code works fine:

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

#10

You are right ! Million and one thanks !!!!!!!!!!!!!!!!!!


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.