Ask coding questions

← Back to all posts
stuck on this one can anyone help
h
mthotchkiss18 (1)

function exerciseThree(userObject){
// Exercise Three: In this exercise you will be given an object called 'userObject'
// The phonne number for this user is incorrect!
// reassign the 'phoneNumber' key to the value: '(951)867-5309'
// return the userObject
userObject=[' phoneNumber'];{
phoneNumber.key = '(951)867-5309';

}
return(userObject);
}

Commentshotnewtop
JustARatherRidi (190)

In JavaScript, an object is basically a collection of key/value pairs. Here's how you would create an object:

const person = {
    name: 'John Doe',
    age: 42,
    hobbies: ['coding', 'biking']
};

Here, name, age, and hobbies are the keys or properties, and 'John Doe', 42, and ['coding', 'biking'] are the corresponding values.


Now, you can access the values in each key either like this

console.log(person.name);
// Prints out 'John Doe' to the console

Or like this

console.log(person['name']);
// Prints out 'John Doe' to the console

Similarly, we can also change or reassign properties in either of the two ways.

person.age += 1;
// Now, 'person.age' is 43.
person['age'] += 1;
// Now, 'person.age' is 43.

So in your case, the object is already there, and it is called userObject. You're asked to change one of its keys, called phoneNumber, to the value '(951)867-5309'. You can do this, again, in one of the two ways.

userObject.phoneNumber = '(951)867-5309';
userObject['phoneNumber'] = '(951)867-5309';

And you're done! Write one of those two lines, and all that's remaining is to return the object, like so:

return userObject;

Hope this helped, let me know if I lost you somewhere!

MIAlien (0)

@JustARatherRidi you're awesome ! I was confused a bit I wasn't sure if I started writing this out correctly since it's a little different from the lecture. I only had "userObject.phoneNumber =" and saw you just added the number value, which was so simple and I understand why. Thank you!

JustARatherRidi (190)

@MIAlien No problem, I'm glad I could help! ^^