freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-an.../basic-javascript/updating-object-properties.md

1.6 KiB

id title challengeType videoUrl forumTopicId dashedName
56bbb991ad1ed5201cd392d1 Updating Object Properties 1 https://scrimba.com/c/c9yEJT4 18336 updating-object-properties

--description--

After you've created a JavaScript object, you can update its properties at any time just like you would update any other variable. You can use either dot or bracket notation to update.

For example, let's look at ourDog:

var ourDog = {
  "name": "Camper",
  "legs": 4,
  "tails": 1,
  "friends": ["everything!"]
};

Since he's a particularly happy dog, let's change his name to the string Happy Camper. Here's how we update his object's name property: ourDog.name = "Happy Camper"; or ourDog["name"] = "Happy Camper"; Now when we evaluate ourDog.name, instead of getting Camper, we'll get his new name, Happy Camper.

--instructions--

Update the myDog object's name property. Let's change her name from Coder to Happy Coder. You can use either dot or bracket notation.

--hints--

You should update myDog's name property to equal the string Happy Coder.

assert(/happy coder/gi.test(myDog.name));

You should not edit the myDog definition.

assert(/"name": "Coder"/.test(code));

--seed--

--after-user-code--

(function(z){return z;})(myDog);

--seed-contents--

// Setup
var myDog = {
  "name": "Coder",
  "legs": 4,
  "tails": 1,
  "friends": ["freeCodeCamp Campers"]
};

// Only change code below this line

--solutions--

var myDog = {
  "name": "Coder",
  "legs": 4,
  "tails": 1,
  "friends": ["freeCodeCamp Campers"]
};
myDog.name = "Happy Coder";