Where am i going wrong? {Im using the literal notation(or whatever its called)}


#1

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(256) 222-2222",
address: ['One Apple Way','LA','CA','93028']
},
agasthya: {
firstName: "Agasthya",
lastName: "Krishna",
number: "(323) 333-3333",
address: ['One Doctor Way','Goregoan East','MH','12345']
}
};

var list = function (friends) {
for (var firstName in friends) {
console.log(firstName);
}
};

var search = function (friends) {
for (var firstName in friends) {
if (firstName === bill) {
console.log(bill);
return bill;
}
}
};


#2

Hey @epicrut! The problem is primarely in your if statement:

You cant just say firstName and the computer automatically knows it (Unless its some type of framework) but this is normal Javascript. to find the firstName you have to acces it by the array then using the dot notation access the first name. Like this:

if(friends[key].firstName === name) {

In your if statement/final step your suppose to both log and return the statement so you just do this:

console.log(friends[key]);
return friends[key];

#3

ok thx. @amanuel2 ur damn awesome at debugging man


#4

@amanuel2 hey bro mind debugging this for me too? :wink:

its saying that I haven't put a "species" property in buddy set to "golden retriever". I am pretty sure I have

// help us make snoopy using literal notation
// Remember snoopy is a "beagle" and is 10 years old.
var snoopy = {
species: "beagle",
age: 10
};

// help make buddy using constructor notation
// buddy is a "golden retriever" and is 5 years old
var buddy = new Object();
buddy.species = ["golden retriever"];
buddy.age = ["5"];


#5

Helo @epicrut

buddy.age is a integer not a string

try with this
buddy.age = [5];


#6

Hey sorry i was sleeping the problem with your code here is that first buddy.age is not a string and second thier not an array. Im not going to do the problem for you but give you an example for you to implement to your problem.

buddy.firstName = "someone"
buddy.age = 90

#7

no problem amanuel sleep all u want. i got the mistake before u answered anyways. sry :wink: @amanuel2


#8

Btw just saying its called Object Literal notation where the dot comes in like this:

buddy.age = 50;

#9

@amanuel2. I'm on 17. "This" works for anyone and in the code its giving me the message "Here's the message: TypeError: Object doesn't support property or method 'setAge' " i don't get y...
// here we define our method using "this", before we even introduce bob

var setAge = function (newAge) {
this.age = newAge;
};
// now we make bob
var bob = new Object();
bob.age = 30;
bob.setAge = setAge;

// make susan here, and first give her an age of 25
var susan = new Object();
susan.age = 25;
// here, update Susan's age to 35 using the method
susan.setAge(35);


#10

Remember to put this line before you set her age, or it wont adress to the function:

susan.setAge=setAge

#11

@amanuel2
ok thx so basically like this right?
// here we define our method using "this", before we even introduce bob
var setAge = function (newAge) {
this.age = newAge;
};
// now we make bob
var bob = new Object();
bob.age = 30;
bob.setAge = setAge;

// make susan here, and first give her an age of 25
var susan = new Object();
susan.age = 25;
// here, update Susan's age to 35 using the method
susan.setAge = setAge;
susan.setAge(35);


#12

Yup @epicrut!!!!!!...


#13

@amanuel2 y is this giving the message that setWidth is undefined??
var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
// here is our method to set the height
rectangle.setHeight = function (newHeight) {
this.height = newHeight;
};
// help by finishing this method
rectangle.setWidth = function (newWidth) {
this.width = newWidth;
};

// here change the width to 8 and height to 6 using our new methods

setWidth(8);
setHeight(6);


#14

@amanuel2 am i bothering and annoying u?


#15

No @epicrut your not.


#16

@amanuel2 then can u answer the question above??


#17

@amanuel2 oh nvm i found my problem. Suuch a sttuuuuppiddd mistake.


#18

Your suppose to write your object before your function name... So like this for example:

rectangle.setLength(10)

#19

yup exactly @amanuel2 found that out. just asking? how do u know so much


#20

I dont know a lot @epicrut. This tutorial guided me much better than codecademy in the object prespective. No Offense to codecademy, but they didnt do a good job of teaching OOP In Javascript.