Codeloft
0 0 XP

Objects

7 min 20 XP + 10 for no hints

An object groups related values under names called properties: let pet = { name: "Milo", age: 3 };

Read a property with a dot: pet.name is "Milo". Change one the same way: pet.age = 4;

Objects and arrays work together. A list of products is an array of objects, and that's how most real app data looks.

Example
let book = { title: "Wonder", pages: 310, read: false };

book.read = true;
console.log(book.title + " has " + book.pages + " pages");
console.log("Finished?", book.read);
Separate properties with commas, and don't forget the colon between each name and its value.

Your tasks

0 of 3 done
  1. student has a name and a numeric age
  2. describe({ name: "Asha", age: 14 }) returns "Asha is 14 years old"Expected "Asha is 14 years old", got undefined
  3. describe works for anyoneExpected "Leo is 9 years old", got undefined

Quick check

Given let car = { color: "red" }, how do you read the color?

student.jsPress Run or Ctrl + Enter
undefined