Loops and arrays II


#1

Hello.I'm a Japanese Univercity student.
I can't solve it.

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

The message is

SyntaxError: Unexpected identifier


#2

Hi inside your for loop this part

int i = 0;

Should be var instead of int


#3

Hello!
Please read the instruction carefully:

Instructions
01. Create an array called names filled with 5 names.
02. Write a for loop that prints "I know someone called " followed by names[i]. Make sure there's a space between "called" and the name!

make you array holds five value.

and try to change the int to var

and one more thing, add spaces between called and "" , like this: I know someone called " not I know someone called"

Hope this helps


#4

This comes across quite confusing, what she's trying to say is add " " which is a space after "I know someone called" like I have shown below.

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


#5

Naaah, sorry. Its a typo error.

Write this line like this:

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

instead of

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

See the difference? Its on the called" and called ". See the space between called and double quote?


#6

Yes but that would add 2 spaces one after called and one by "adding" a space +" "+ but the exercise requires only one so either the one after called or the added one.


#7

Sorry my fault. i already edited my reply post.
@meinakazato hope this time, you got it right and your codes run smoothly :slightly_smiling:


#8

@benjnev
@wizmarco
@haxor789
@gracie017

Thank you everyone.
I can't notice the mistake!


#9

@meinakazato

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

Try that