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.
2
Answers
Your wonAward setter is defined outside the movie object, and the last couple of chars (
};
) of your code shouldn’t be there:You can then use your setter like so:
movie.wonAward = "Razzie";
.It seems like you’re trying to define the function wonAward as a setter function inside the movie object. To achieve this, you need to use the Object.defineProperty method or use ES6 shorthand for defining setter functions. Here is the corrected version of your code:
In this code snippet, I’ve used Object.defineProperty to define the wonAward property as a setter on the movie object. You can then use this setter function to push the name of the award onto the awards array. Check if this works for you and if you still have any errors share them here