Define a method named roleOf that takes the name of an actor as an argument and returns that actor's role. If the actor is not in the movie return "Not in this movie.". Ex: roleOf("Viggo Mortensen") returns "Aragorn". Hint: A method may access the object's properties using the keyword this. Ex: this.cast accesses the object's cast property.

Respuesta :

Answer:

var movie = {

   name: "Avengers Endgame",

   director: "Joe Russo",

   composer: "Alan Silvestri",

   cast: {

       "Scarlett Johansson": "Black Widow",

       "Chris Evans": "Captain America"      

   },

   roleOf: function (name) {

       if (typeof (this.cast[name]) !== 'undefined') {

           return this.cast[name];

       } else {

           return "The actor is not part of this movie";

       }

   }

};

     

Explanation:

  • Initialize the movie JSON (JavaScript Object Notation) having the name, director, composer and cast properties.
  • Define a roleOf: function that has a name parameter.
  • Check whether the selected is not equal to undefined and then return that name.
  • Otherwise display this message: "The actor is not part of this movie".