Did you create a function called list?


#1


https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/6?curriculum_id=506324b3a7dffd00020bf661


ReferenceError:Friends is not defined
"Did you create a function called list?"


Friends.steve = {
   firstName: "Steve",
   lastName: "Jobs",
   Gender: "Male",
   Hobby: "Being in the cemetry",
   number: 0723746223,
   address: ["3rd row from the back, 2 from the left, Rivington Cemetry"]
};
Friends.bill = {
   firstName: "Bill",
   lastName: "Gates",
   Gender: "Male",    
   Hobby: "Making Dodgy Operating Systems",
   number: 0723492462784,
   address: ["10 Downing Street", "Syria"]
};
var list = function (Friends) {
    for (var key in Friends) {
        console.log(Friends[firstName]);
    }
};
list (Friends);


#2

i don't see you define friends anywhere? So seems like a fair error message


#3

Friends = {
firstName: "Steve",
lastName: "Jobs",
Gender: "Male",
Hobby: "Being in the cemetry",
number: 0723746223,
address: ["3rd row from the back, 2 from the left, Rivington Cemetry"]
};
Friends.bill = {
firstName: "Bill",
lastName: "Gates",
Gender: "Male",
Hobby: "Making Dodgy Operating Systems",
number: 0723492462784,
address: ["10 Downing Street", "Syria"]
};
var list = function (Friends) {
for (var key in Friends.bill) {
console.log(Friends.bill[firstName]);
}
};
list (Friends.bill);

I defined friends but it still doesn't recognize the list function for some reason.


#4

i am a bit confused what you are doing.

You should first create an object named friends, then we have two options:
create empty friends object, add bill and steve
create bill and steve directly inside friends object

then please read the instructions again what the list function should do


#5

Well I've done that, exactly how it showed me to do in the previous lesson, yet I'm still getting error messages now.

Friends = {
    steve: {
   firstName: "Steve",
   lastName: "Jobs",
   Gender: "Male",
   Hobby: "Being in the cemetry",
   number: 0723746223,
   address: ["3rd row from the back, 2 from the left, Rivington Cemetry"]
    }
};
    
    bill: {
   firstName: "Bill",
   lastName: "Gates",
   Gender: "Male",    
   Hobby: "Making Dodgy Operating Systems",
   number: 0723492462784,
   address: ["10 Downing Street", "Syria"]
    
       }
    }
}
var list = function (random) {
    for (var key in Friends) {
        console.log(Friends[key]);
    }
};
list (random);

// var friends = {
// bill: {

I have even notified myself of the correct syntax yet this still doesn't work. Unless I'm supposed to mess with the curly braces, but I've already tried that and it still doesn't work. Here are the error messages that pop up:

SyntaxError: Expected ' ; '
Line 13: Label 'firstName' on Bill statement.
Line 15: Missing ; before statement.
Expected '(end)' and saw ';'
Line 14: Missing ; before statement.
Expected '}' to match '{' from line 12 and instead saw ';'.


#6

now you have friends object containing steve, but bill is not part of Friends object? the }; here:

address: ["3rd row from the back, 2 from the left, Rivington Cemetry"]
    }
}; // this one

ends declaration of Friends object


#7

Well I've gotten rid of the }; on line 10, which solved those other errors, but brought more errors on line 10.

Console: SyntaxError: Unexpected identifier
Line 11: Expected '}' to match '{' from line 1 and instead saw 'bill'.
Missing ';' before statement.
Expected (end) and instead saw ':'.

Maybe try the link here: "https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/6?curriculum_id=506324b3a7dffd00020bf661" to solve the problems and get me step by step how to get to no errors and it's functional without any errors relating to how it's not doing as intended.


#8

hello there..
Lets break your code in parts and analyse...
@guywhoisterribleatsc
I have pointed out mistakes you made.
The first part...
It has many errors.
Like you have used excess of curly brackets
You have also used semicolon instead of comma

I have pointed those spots where you made mistakes..

Now...
what things you have to do now..
1.The things I have rounded,You have to delete them.
2.You can see I marked number ,They should be strings,surround them between quotes..
like .. "2474747474"
3.You can see I marked 9 ,actually its comma, make a comma there.

Now lets understand what you have to do and what you were doing..

You had to create a Object which carries two Objects corresponding to two keys.
Now lets see an example...

if Z is an Object and it has two Objects corresponding to two keys (key1 and key2)inside it,It will be like this.

Z = {
    key1: {"a": 1, "b": 2}
    ,
    key2: {"c": 3, "d": 5}
}

If you observe then you will see that I have separated them using comma?
and number of starting curly brackets { and closing brackets } are same?
Is there any semicolons ; inside it? No

You did all 3 mistakes!

Now lets see second part of your code...

var list = function (random) {
    for (var key in Friends) {
        console.log(Friends[key]);
    }
};

When we create a function ,we create it to solve so many questions not just one.

Now lets see your code line by line..

1.You created a function called list then you put parameter named random.
not to forget that random is any Object.

2.You're using for loop to iterate over input parameter(i.e is random) but you're iterating on Friends?
There you making mistake...
Your object is random that you take as input not Friends.

so replace Friends with random?

3.You're printing value of object ?but you had to print just key (names)?

last part,,,

list (random);

You don't need this code.remove it.
CC interpreter will test your code, by automatically providing inputs.

I'll highly suggest you to reread the theory and read the instruction again!
do reply if you get it or not.


#9

Ah, thank you for the much needed reply! I did notice the excessive amount of curly braces, but I was focused on trying to find out the errors. Codecademy tells me to put a semi-colon next to curly brackets, not sure why. I don't really understand the commas between the two corresponding "sub objects", since Codecademy hasn't seemed to tell me about that, unless I'm really forgetful! I kind of didn't expand more on the parameter for the list function, since I got confused with the for loop placeholder. The last part was for calling the function, still unsure if I even needed to. I still got much to learn about JavaScript (first proper coding language).

EDIT: The code has no error messages, however it won't let me pass and keeps asking whether I made a list function or not. I've reread your post and corrected my mistakes. I probably made a mistake in my post, but I will check tomorrow properly about what the mistake is (not got much time).


#10

In second part of code I have mentioned this..

3.You're printing value of object ?but you had to print just key (names)?

console.log(random[key]); // here you've to print key not value (random[key]) ?

try to just print key ?
Try that and reply if it worked or not?


#12

I've tried that but that hasn't really changed anything. I did get a email notification off a guy who posted here 4h ago from when I posted this who suggested to call the function, which made a difference and printed just steve and bill, but that still didn't work with Codecademy, despite doing as asked. Can't find that guys post on this forum though, which is a bit odd.


#13

Change variable name Friends to friends
(as I have last tested ,It did not let me pass but changing Case(Friends to friends) made a difference)

Reason: At very beginning of the section it was in the instruction..

Create an object called friends. Feel free to use either object literal notation or the object constructor. Check the Hint if you need a syntax reminder.


#14

Ah thanks. Took you long enough but better than the moderator :wink:


#15

Without mod I'd have not known about this post! respect ! :slight_smile: :thumbsup:
youre welcome!


#16

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