Last active
May 6, 2021 02:52
-
-
Save delonnewman/ee21829144eef4cb63b2d2302dc13a21 to your computer and use it in GitHub Desktop.
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
function MovieMaker(name) { | |
var ticketsSold = 0; | |
document.write( | |
`<div className="Movie" id="movie-${name}"> | |
<h4>${name}</h4> | |
<button id="Buyone-${name}">Buy one</button> | |
<button id="Familypack-${name}">Family pack</button> | |
</div>` | |
); | |
var elem = document.getElementById(`Buyone-${name}`); | |
elem.onclick = function() { | |
ticketsSold++; | |
}; | |
var elem = document.getElementById(`Familypack-${name}`); | |
elem.onclick = function() { | |
ticketsSold += 5; | |
}; | |
return { | |
name: name, | |
ticketsSold: function() { return ticketsSold } | |
}; | |
} | |
var movies = [ | |
MovieMaker("Jocker"), | |
MovieMaker("Last Chance Harvey"), | |
MovieMaker("The same kind of diffrent as me") | |
]; | |
setInterval(function(){ | |
movies.forEach(function(movie) { | |
console.log(movie.ticketsSold(), ' tickets sold for ', movie.name); | |
}); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment