JS Assignment 11: Intro to Objects
h
Paultheriault (3)

//This one has got me stumped. Any hints or advice would be greatly appreciated.//

function exerciseTwo(animal){
// Exercise Two: In this exercise you will be given an object called 'animal'
// Create a new variable called 'animalName'
// Accessing the animal object, assign the 'animalName' variable to the 'latinName' key on the object.
// return the animalName variable.

}

You are viewing a single comment. View All
Answered by heyitsmarcus (287) [earned 5 cycles]
View Answer
heyitsmarcus (287)

Hey @Paultheriault,

You can access the properties of an object like so:

object.property

So, if I want to set a variable to an object's property, I can create the variable and at the same time, assign it the object's property:

let variable = object.property;

You've got this! Happy Coding!

heyitsmarcus (287)

@Paultheriault You are very close! Remember animalName is just a variable itself. And when you're accessing properties of an object, you do object.property (or object[property] but that will come later).

So, you need:

//animalName is assigned the value stored in animal's property "latinName"
let animalName = animal.latinName;
return animalName;

So, to put it all together:

function exerciseTwo(animal){
  // Exercise Two: In this exercise you will be given an object called 'animal'
  // Create a new variable called 'animalName'
  // Accessing the animal object, assign the 'animalName' variable to the 'latinName' key on the object.
  // return the animalName variable.

  //animalName is assigned the value stored in animal's property "latinName"
  let animalName = animal.latinName;
  return animalName;
}
Paultheriault (3)

@heyitsmarcus I probably need to give it a rest for a while, but I feel like I am close and yet cannot seem to get any error except for the one that keeps saying that exerciseOne is undefined. Am I on the right track or way off base?
let double = x * x;
mathHelers.double;{
}

heyitsmarcus (287)

@Paultheriault I'm not sure where the variable double is coming from. Be sure to read the directions carefully. You need to create a variable called animalName and you will be passed in an object called animal which has a property called latinName.

If you're still stuck after that, I'll drop you another hint.

Paultheriault (3)

@heyitsmarcus sorry, got my windows mixed up when answering replies. Think I better have an extra cup of coffee before I jump back into this.

heyitsmarcus (287)

@Paultheriault Ah no worries! Please let me know if you figure it out

Paultheriault (3)

@heyitsmarcus Still struggling with this one for some reason.
function exerciseTwo(animal){
// Exercise Two: In this exercise you will be given an object called 'animal'
// Create a new variable called 'animalName'
// Accessing the animal object, assign the 'animalName' variable to the 'latinName' key on the object.
// return the animalName variable.
let animalName = {animal:latinName
};
animalName: 'latinName';{animalName}
}
I remember taking notes on object properties, but I have been manipulating this code for hours and now it just looks like gobbly-gook to me.

heyitsmarcus (287)

@Paultheriault I hope it makes more sense to you after that.

Paultheriault (3)

@heyitsmarcus I could have sworn that I tried that about a dozen times, but my coding must have been off somewhere. Thank you very much for your help.

heyitsmarcus (287)

@Paultheriault You're very welcome. It looks like you were on the right path, but you were overcomplicating it just a little bit. Hopefully accessing those properties seems quite a bit easier, right? haha

Paultheriault (3)

@heyitsmarcus I would agree about overcomplicating the solution, but we all have to be good at something in life. Right? I still need some practice with them so I'm powering through GitHub's Javascript Boot Camp while finishing the last couple of sections here on Web Development. Thanks again.

heyitsmarcus (287)

@Paultheriault That's too funny! XD I highly, highly recommend giving FreeCodeCamp a try: http://freecodecamp.org. It is an excellent and interactive tutorial that will greatly enhance all of your web development skills. And it's totally free.

Paultheriault (3)

@heyitsmarcus Sweet, I will def check it out!

jjaime12 (1)

@heyitsmarcus function exerciseOne(){}
// Exercise One: In this exercise you will create a variable called 'aboutMe'
// This variable should be assigned a new object
// In this object create three key:value pairs
// The keys should be: 'name', 'city', 'favoriteAnimal'
// The values should be strings associated with the keys.
// return the variable 'aboutMe'
const aboutMe = {
name: 'jose',

city: 'bell gardens',

favoriteAnimal: 'lion',

}

heyitsmarcus (287)

@jjaime12 just be sure you're returning aboutMe. So write return aboutMe; after the object and you should be good.