The question:
Define a setter function named wonAward() that takes a parameter for the name of an award and pushes the award name onto the end of the awards array.
My code:
let movie = {
title: "Interstellar",
director: "Christopher Nolan",
composer: "Hans Zimmer",
budget: 165000000,
boxOffice: 675100000,
awards: [],
};
/* Your solution goes here */
set wonAward(nameAward) {
this.awards.push(nameAward);
}
};
The Error:
Error: (line 14) Uncaught SyntaxError: Unexpected identifier
‘wonAward’. The code editor above may provide more details for this
error
.
Note: Although the reported line number is in the uneditable part of the code, the error actually exists in your code. Tools often don’t recognize the problem until reaching a later line.
I have been working on this problem for 3 hours and it is a small question in a huge homework assignment. I am changing my major.
To solve this problem, I already laid it all out earlier.
>Solution :
Your wonAward setter is defined outside the movie object, and the last couple of chars ( };) of your code shouldn’t be there:
let movie = {
title: "Interstellar",
director: "Christopher Nolan",
composer: "Hans Zimmer",
budget: 165000000,
boxOffice: 675100000,
awards: [],
set wonAward(nameAward) {
this.awards.push(nameAward);
}
};
You can then use your setter like so: movie.wonAward = "Razzie";.