Skip to content

Instantly share code, notes, and snippets.

@abhiaiyer91
Created July 26, 2019 16:16
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 abhiaiyer91/c8f698df1a97e0418487fc0150a05440 to your computer and use it in GitHub Desktop.
Save abhiaiyer91/c8f698df1a97e0418487fc0150a05440 to your computer and use it in GitHub Desktop.
// 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