Challenge: Modify and Extend an Object
Task
You're given an object, student
, representing a student's information. Your task is to modify existing properties and add new properties.
Modify the student's age to be
21
.Add a new property called
grade
and set it to"A"
.
99
1
2
3
4
5
6
7
8
9
10
11
12
13
const student = {
name: "Pauline Reilly",
age: 24,
major: "Humanities",
};
// Task 1: Modify `age` to `21`
___ = ___
console.log(student.age); // Output: 21
// Task 2: Add a new property `grade`
___ = ___
console.log(student.grade); // Output: A
12345678910111213const student = { name: "Pauline Reilly", age: 24, major: "Humanities", }; // Task 1: Modify `age` to `21` ___ = ___ console.log(student.age); // Output: 21 // Task 2: Add a new property `grade` ___ = ___ console.log(student.grade); // Output: A
Expected output:
91221A
To modify a property's value, use assignment with dot notation.
To add a new property, use the assignment with dot notation, providing the property name and value.
99
1
2
3
4
5
6
7
8
9
10
11
12
13
const student = {
name: "Pauline Reilly",
age: 24,
major: "Humanities",
};
// Task 1: Modify `age` to `21`
student.age = 21;
console.log(student.age); // Output: 21
// Task 2: Add a new property `grade`
student.grade = "A";
console.log(student.grade); // Output: A
12345678910111213const student = { name: "Pauline Reilly", age: 24, major: "Humanities", }; // Task 1: Modify `age` to `21` student.age = 21; console.log(student.age); // Output: 21 // Task 2: Add a new property `grade` student.grade = "A"; console.log(student.grade); // Output: A
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 8
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår