Ask 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 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.

+2
Answers (1)
  1. 15 June, 19:59
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers