Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

the function named roleof () takes the name of an actor and a cast as a…

Question

the function named roleof () takes the name of an actor and a cast as arguments. write a return statement that ret role that corresponds to the actors name in the cast map. ex: roleof (\jessica chastain\, cast) returns \murph\. let cast = { // code will be tested with different actors \matthew mcconaughey\: \cooper\, \anne hathaway\: \brand\, \jessica chastain\: \murph\, \matt damon\: \mann\, \mackenzie foy\: \young murph\ }; function roleof(actorname, cast) { / your solution goes here / }

Explanation:

Step1: Access the value in the cast object

In JavaScript, to access a property (in this case, the role corresponding to an actor's name) of an object, we use the syntax objectName[propertyName]. Here, the cast is the object and actorName is the property (key) whose associated value (the role) we want to retrieve.

Step2: Return the retrieved value

The function roleOf is supposed to return the role. So we use the return statement followed by the expression that accesses the correct value from the cast object.

Answer:

return cast[actorName];