How do I keep getting this wrong?!


#1


var names["Zac","Mariah","Elijah","Fives","Brandon"];

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


#2

I keep getting the message unexpected token [


#3

you need to set names equal to the array. Like

var names = ["Zac","Mariah","Elijah","Fives","Brandon"];

Also, in the for loop, you need to log names[i] because i is incrementing. (if you dont, it will print "I know someone calledMariah" 5 times.)

I will also suggest putting a space between called and the end quotation mark.


#4

var names = ["Mariah","Zac","Elijah","Fives","Brandon"];

for (var i = 0; i < names.length; i ++) {
console.log ("I know someone called" + names[0]);
};
I can't get the space to appear..... What do I do? :confused:


#5

Leave a space just before the string concatenation...

e.g console.log("text " + variable);


#6

Okay, thanks :smile: :smile_cat: :slight_smile: :smiley:


#7

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