Ask Question
6 December, 03:02

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.

+3
Answers (1)
  1. 6 December, 04:28
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers