Hello everyone, I need to make a function that will display certian text using For loop. Can anyone help me?
const students = [
{ name: “John”, city: “New York” },
{ name: “Peter”, city: “Paris”},
{ name: “Kate”, city: “Sidney” }
]
I need to have console.log
to display "<Name>
lives in <city>
"
miku86
2
Hey there,
what’s your guess how to solve it?
1 Like
Hi,
I was going for
for(let i = 0; i < students.length; i++){
console.log(students.name[i] + " "+ "lives in" + " " + students.city[i]);
miku86
4
Good first try.
So what does the error say?
And why?
I got "Uncaught SyntaxError: Invalid or unexpected token "
And I have no idea why 
miku86
6
Mostly caused by a wrong bracket.
Did you close all open brackets like ()
and {}
?
Now I got this “TypeError: Cannot read property ‘0’ of undefined”
miku86
8
Nice!
So there’s this thing students.name[i]
.
What do you want to do there?
2 Likes
I want to select the value of the each name key each time
1 Like
I like how you are allowing him to figure it out 
2 Likes
How do you select an element in an array?
1 Like
miku86
12
So how can you access one specific student?
2 Likes
You forgot }
for(let i = 0; i < students.length; i++){
console.log(students.name[i] + " "+ “lives in” + " " + students.city[i]);
1 Like
Hey if you don’t know say you don’t know. We are trying to help you 
2 Likes
students[0] for the first one and so on for the rest?
1 Like
I have figured it out now, I’ve placed [i] at the wrong position, thanks a lot!
2 Likes
miku86
18
Glad you managed to solve it! 
1 Like