Last active
October 1, 2022 09:31
-
-
Save buymed-hoangpham/120717b67b4d3de56cfc31bcad80caf6 to your computer and use it in GitHub Desktop.
3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Write the Movie type alias to make the following two variables properly typed | |
| // Make sure that "originalTitle" is optional and "title" is readonly | |
| type BoxOffice = { | |
| budget: number; | |
| grossUS: number; | |
| grossWorldwide: number; | |
| } | |
| type Movie = { | |
| title: string; | |
| originalTitle?: string; | |
| director: string; | |
| releaseYear: number; | |
| boxOffice: BoxOffice | |
| } | |
| const dune: Movie = { | |
| title: "Dune", | |
| originalTitle: "Dune Part One", | |
| director: "Denis Villeneuve", | |
| releaseYear: 2021, | |
| boxOffice: { | |
| budget: 165000000, | |
| grossUS: 108327830, | |
| grossWorldwide: 400671789, | |
| }, | |
| }; | |
| const cats: Movie = { | |
| title: "Cats", | |
| director: "Tom Hooper", | |
| releaseYear: 2019, | |
| boxOffice: { | |
| budget: 95000000, | |
| grossUS: 27166770, | |
| grossWorldwide: 73833348, | |
| }, | |
| }; | |
| // Write a function called getProfit that accepts a single Movie object | |
| // It should return the movie's worldwide gross minus its budget | |
| // For example... | |
| // getProfit(cats) => -21166652 | |
| const getProfit = (movie: Movie):number => movie.boxOffice.grossWorldwide - movie.boxOffice.budget; | |
| console.log(getProfit(dune)) | |
| console.log(getProfit(cats)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment