9/33 Accessing Properties, Part 2 [need help!]

// Take a look at our next example object, a dog
var dog = {
species: “greyhound”,
weight: 60,
age: 4
};

var species = dog[“species”];
// fill in the code to save the weight and age using bracket notation
var weight = dog[60];
var age = dog[4];

Oops, try again. Make sure to save the dog’s weight into ‘weight’.
thanks in advance,

// Take a look at our next example object, a dog
var dog = {
species: “greyhound”,
weight: 60,
age: 4
};

var species = dog[“species”];
// fill in the code to save the weight and age using bracket notation
var weight =dog[“weight”];
var age =dog[“age”];

what is wrong with my code
// Take a look at our next example object, a dog
var dog = {
species: “greyhound”
weight: 60
age: 4
};

var species = dog[“species”];
// fill in the code to save the weight and age using bracket notation
var weight = dog[60];
var age = dog[4];

@alvareztitans75,

myObj = {
type: ‘fancy’,
disposition: ‘sunny’
}

myObj has 2 properties seperated by a comma-,
a type property with property-key type and an associated string VALUE ‘fancy’
a disposition-property with property-key disposition and
…an associated string VALUE ‘sunny’.

= = = = = = = = = = = = = = = = = = = = = = =

To create an Object,

you can use the literal notation,

you directly create an Instance of the object, with the
properties being separated by a comma-,
var myObj = {
type: ‘fancy’,
disposition: ‘sunny’
};

should be like this

// Take a look at our next example object, a dog
var dog = {
species: “greyhound”,
weight: 60,
age: 4
};

var species = dog[“species”];
// fill in the code to save the weight and age using bracket notation
var weight = dog[“weight”];
var age = dog[“age”];

var dog = {
species: “greyhound”
weight: 60
age: 4
};

var species = dog[“species”];
// fill in the code to save the weight and age using bracket notation
var weight = dog[“weight”] = 30;
var age = dog[age] = 10;

console.log(dog)

@pyrunner31586,

In your literal notated dog object
you are forgetting the comma-
,**
with which you separate the properties from each other

var dog = {
    species: "greyhound",
    weight: 60,
    age: 4
};

Then as you are trying to use
a non-declared =age= variable in your dog[age]
the code

var weight = dog["weight"] = 30;
var age = dog[age] = 10;
console.log(dog)

would a1st run result in

{ species: 'greyhound', weight: 30, age: 4, undefined: 10 }

and in the 2nd run would give a result

{ '10': 10, species: 'greyhound', weight: 30, age: 4 }

2 Likes

var dog = {
species: “greyhound”,
weight: 60,
age: 4
};

var species = dog[“species”];
// fill in the code to save the weight and age using bracket notation
var weight = dog[‘weight’];
var age = dog[‘age’];

try this… this is crct…

1 Like

Where you went wrong is with var weight = dog[60].

To sum it up, you’re giving it a number instead of the property itself, which it is asking for, so instead of this var weight = dog[60] you want this var weight = dog["weight"] so it save the property in the object opposed to the number.

Hope this helped :slight_smile: