Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Retrieve Object Property Values | Fundamentals of JavaScript Objects
JavaScript Data Structures

bookChallenge: Retrieve Object Property Values

Task

You're given an object, user, representing a person's hobbies and interests. Your task is to access and retrieve specific details from the object.

  • Access and log the person's name.
  • Access the indoor hobby and log it to the console.
  • Store the person's age in a variable.
  • Access the favorite music genre and log it.
12345678910111213141516171819202122232425
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(___); // person's name // Task 2 console.log(___); // indoor hobby // Task 3 const userAge = ___; console.log(userAge); // person's age // Task 4 console.log(___); // music genre
copy

Expected output:

Sarah
painting
32
jazz
  1. Use dot notation to access properties within an object.
  2. To access properties within nested objects and arrays, chain the dot notation and square brackets (if needed).
  3. Use assignment with dot notation to store property values in variables.
123456789101112131415161718192021222324
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(user.name); // person's name // Task 2 console.log(user.hobbies.indoor); // indoor hobby // Task 3 const userAge = user.age; console.log(userAge); // person's age // Task 4 console.log(user.preferences.music); // music genre
copy

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 6

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Awesome!

Completion rate improved to 2.27

bookChallenge: Retrieve Object Property Values

Svep för att visa menyn

Task

You're given an object, user, representing a person's hobbies and interests. Your task is to access and retrieve specific details from the object.

  • Access and log the person's name.
  • Access the indoor hobby and log it to the console.
  • Store the person's age in a variable.
  • Access the favorite music genre and log it.
12345678910111213141516171819202122232425
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(___); // person's name // Task 2 console.log(___); // indoor hobby // Task 3 const userAge = ___; console.log(userAge); // person's age // Task 4 console.log(___); // music genre
copy

Expected output:

Sarah
painting
32
jazz
  1. Use dot notation to access properties within an object.
  2. To access properties within nested objects and arrays, chain the dot notation and square brackets (if needed).
  3. Use assignment with dot notation to store property values in variables.
123456789101112131415161718192021222324
const user = { name: "Sarah", age: 32, hobbies: { outdoor: "hiking", indoor: "painting", }, preferences: { music: "jazz", movieGenre: "sci-fi", }, }; // Task 1 console.log(user.name); // person's name // Task 2 console.log(user.hobbies.indoor); // indoor hobby // Task 3 const userAge = user.age; console.log(userAge); // person's age // Task 4 console.log(user.preferences.music); // music genre
copy

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 6
some-alt