31. properties plz help


#1

var snoopy = new Object();
snoopy.species = "beagle";
snoopy.age = 10;

var age = 10,
var species = beagle,// save Snoopy's age and species into variables
// use dot notation for snoopy's species
snoopy.species

snoopy[10]

this is my code idk why its not working even though you practice this in the previous exercises


#3

almost, the result of snoopy.species should be stored in species.

Same for age, you should store the result of snoopy's age in variable called age, but using the square bracket notation instead

@jlanssie posting answers without explanation is not according to the guidelines
@


#4

Chipninja73928 I just had trouble with the same task and eventually found a solution.

var snoopy = new Object();
snoopy.species = "beagle";
snoopy.age = 10;

var age = 10,
var species = beagle,// save Snoopy's age and species into variables
// use dot notation for snoopy's species
snoopy.species

snoopy[10] <----- I think you're issue may be here.

this is my code idk why its not working even though you practice this in the previous exercises

It looks to me that when you're calling the object snoopy using bracket notation that you are passing it a hardcoded number as a property. Try passing it the name of the property inside parentheses, so that you have something as below:

var age = snoopy["age"];

The above code follows the rule -> var variableName = objectName["_propertyName_"];

I hope this helps :slight_smile:

Mike


#5

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