Created
February 1, 2023 18:44
-
-
Save telagraphic/c72989ba38620a1e40bd39ad6cb636ec 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
<!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