Created
July 26, 2019 16:16
-
-
Save abhiaiyer91/c8f698df1a97e0418487fc0150a05440 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
// You're hosting an event, and the admission tickets are expensive. Groups of people are trying to cheat the system by using the same tickets multiple times. Stop them! | |
// 1) Create a constructor function called Ticket that takes one parameter, code, and creates a Ticket object. | |
// The Ticket object will have the following parameters: | |
// code : a string that stores the ticket code | |
// used : a boolean that stores whether or not the ticket has been used yet | |
// useTicket: a function registers that the ticket has been used and prevents reuse or tampering | |
// 2) Create a function called validTicket to check whether the ticket is valid and return true or false. For a ticket to be valid, | |
// the ticket code must match the correct code, and the ticket must be unused. | |
function Ticket(code){ | |
this.code = code; | |
this.used = false; | |
this.useTicket = function(){ | |
this.used = true; | |
Object.freeze(this); | |
} | |
} | |
function validTicket(ticket, correctCode){ | |
return !ticket.used && ticket.code == correctCode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment