Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

6.10.1: objects. jump to level 1 define a getter function named totalre…

Question

6.10.1: objects.
jump to level 1
define a getter function named totalrevenue () that subtracts budget from boxoffice and returns the result.
note: the declaration of a getter begins with the keyword get. the getter returns a value using the keyword return.
1 // code will be tested with a different movie
2 let movie = {
3 title: \pirates of the caribbean: at worlds end\,
4 director: \gore verbinski\,
5 composer: \hans zimmer\,
6 budget: 300000000,
7 boxoffice: 963400000,
8 awards: ,
9
10 / your solution goes here /
11
12 };

Explanation:

Step1: Define the getter function

According to the note, the getter function should start with get. So we define get totalRevenue().

get totalRevenue()

Step2: Return the subtraction result

The function needs to return boxOffice - budget. So the complete function is:

get totalRevenue() {
    return this.boxOffice - this.budget;
}

Answer:

// Code will be tested with a different movie
let movie = {
    title: "Pirates of the Caribbean: At World's End",
    director: "Gore Verbinski",
    composer: "Hans Zimmer",
    budget: 300000000,
    boxOffice: 963400000,
    awards: [],
    // Your solution goes here
    get totalRevenue() {
        return this.boxOffice - this.budget;
    }
};