Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can someone help me debug this code? I am highly confused why I get an error

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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";.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading