Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Created February 1, 2023 18:44
Show Gist options
  • Save telagraphic/c72989ba38620a1e40bd39ad6cb636ec to your computer and use it in GitHub Desktop.
Save telagraphic/c72989ba38620a1e40bd39ad6cb636ec to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Treasure Chest</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
margin: 0 auto;
max-width: 40em;
width: 88%;
}
</style>
</head>
<body>
<h1>Treasure Chest</h1>
<p>All of the magic here happens in the console.</p>
<script>
let TreasureChest = (function() {
function Constructor() {
this.bronze = 0;
this.silver = 0;
this.gold = 0;
}
Constructor.prototype.addBronze = function(bronze) {
this.bronze = this.bronze + bronze;
}
Constructor.prototype.addSilver = function(silver) {
this.silver = this.silver + silver;
}
Constructor.prototype.addGold = function(gold) {
this.gold = this.gold + gold;
}
Constructor.prototype.getLoot = function() {
console.log(`
Bronze stock is ${this.bronze}
Silver stock is ${this.silver}
Gold stock is ${this.gold}
`);
}
return Constructor;
})();
let chest = new TreasureChest();
chest.addBronze(10);
chest.getLoot();
chest.addSilver(20);
chest.getLoot();
chest.addGold(30);
chest.getLoot();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment