QUESTION IMAGE
Question
the function named deletefrommovie () takes the name of an actor and a cast as arguments. if the actor is in the cast, delete that actor from the cast and return actor deleted. otherwise, return not in this cast.
ex: deletefrommovie (\keira knightley\) returns actor deleted.
1 let cast = { // code will be tested with different actors
2 \johnny depp\: \jack sparrow\,
3 \orlando bloom\: \will turner\,
4 \keira knightley\: \elizabeth swann\,
5 \geoffrey rush\: \hector barbossa\
6 };
7
8 function deletefrommovie(actorname, cast) {
9
10 / your solution goes here /
11
12 }
Step1: Check if actor exists
Use if (actorName in cast) to check if the actor is in the cast object.
Step2: Delete actor if exists
If exists, use delete cast[actorName] to remove the actor from the cast object and return "Actor deleted".
Step3: Return message if not exists
If not exists, return "Not in this cast".
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
function deleteFromMovie(actorName, cast) {
if (actorName in cast) {
delete cast[actorName];
return "Actor deleted";
}
return "Not in this cast";
}