Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active May 31, 2022 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/3c0d6d285a537041900a92f71c9c73c8 to your computer and use it in GitHub Desktop.
Save mcsee/3c0d6d285a537041900a92f71c9c73c8 to your computer and use it in GitHub Desktop.
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