Function syntax


#1

sorry for the long post but i think it'll be a quick fix if yall can help.

here's the code:

var friends = {
bill: {
firstName: "Bill",
lastName: "Jones",
number: 000-000-0001,
address: ['123 Main St.', 'Small Town', 'TX', '12345']
},
steve: {
firstName: "Steve",
lastName: "Smith",
number: 000-000-0002,
address: ['125 Main St.', 'Small Town', 'TX', '12345']
}
};
var list = function (phonebook)
{
for (true) {
console.log(friends);
}
};

here's the error:

SyntaxError: Unexpected token )

and it's talking about the syntax of the function.

here's the instructions:

-Create a function list that takes a single parameter.
-In the body of the function, write a for/in loop.
-In the loop, use console.log to print out the key. (For example, if you only have bill and steve as entries, list should just print out "bill" and "steve".)

THANK YOU!


#2

The problem is with the syntax of the loop inside the list function here:

for(true) is not valid syntax. You can read about for/in loop here. See the examples.

Also you can't use friends variable inside the function list because is undefined in this scope. You can use the parameter of the function - phonebook.


#3

I appreciate all that but I still cant figure out what to do, how to fix it/what to use


#4

Change your for loop to if.


#5

even though the instructions say to use a for/in loop?


#6

Here is example how to use for/in loop to list the properties of object:

var obj = {a:1, b:2, c:3};
    
for (var prop in obj) {
  console.log(prop);
}

Try to think how to use it in your function to list the properties of friends.


#7

That helped! Thank you so much!