Ask coding questions

← Back to all posts
Assignment 11; Intro to objects
Paultheriault (2)

//Having trouble reassigning the value of the userObject phoneNumber. How does one write a replacement in a single variable function?
Any tips would be greatly appreciated.
//
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
const phoneNumber = ['userObject'];
userObject[0] = "(951)867-5309";
console.log(userObject);
}
exerciseThree();

Answered by vedprad1 (725) [earned 5 cycles]
View Answer
Commentshotnewtop
vedprad1 (725)

This is in js:
I think you are very confused on how to work with objects. I would go to w3schools.com to learn more. Here is the answer, though:

function exerciseThree(userObject) {
  userObject.phoneNumber = '(951)867-5309';
  return userObject;
}

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!

Paultheriault (2)

@vedprad1 Thank you. Needed to take a break as I was getting extremely mixed up.

vedprad1 (725)

@Paultheriault : Could you please mark my answer as correct? Thanks!

ebest (574)

What language is this? Java right?

phoneNumber[0] = "(951)867-5309";

but I don't know if you can reassign consts...

vedprad1 (725)

@ebest : This is in js, not java, but the answer would be the same. The only difference would be replacing function with the type of Object.

Your answer is incorrect because phoneNumber is not an array.