Ask Question
6 November, 09:16

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.

+1
Answers (1)
  1. 6 November, 09:58
    0
    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 (jа vascript 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".
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers