Last active
May 31, 2022 00:42
-
-
Save mcsee/3c0d6d285a537041900a92f71c9c73c8 to your computer and use it in GitHub Desktop.
This file contains 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
class Movie { | |
constructor(rate) { | |
this.rate = rate; | |
} | |
} | |
class Moviegoer { | |
constructor(age) { | |
this.age = age; | |
} | |
watchMovie(movie) { | |
if ((this.age < 18) && (movie.rate == 'Adults Only')) | |
throw new Error("You are not allowed to watch this movie"); | |
// watch movie | |
} | |
} | |
let jane = new Moviegoer(12); | |
let theExorcist = new Movie('Adults Only'); | |
jane.watchMovie(theExorcist); | |
// Jane cannot watch the exorcist since she is 12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment