Created
April 7, 2022 01:10
-
-
Save Verdagon/e579f89d4aac7ecd05b0514939686f4c 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
let accounts = []; | |
accounts.push({ name: "Bob", money: 100, labelView: null }); | |
accounts.push({ name: "Cindy", money: 100, labelView: null }); | |
accounts.push({ name: "Reginald", money: 100, labelView: null }); | |
accounts.push({ name: "Jim Argalax", money: 100, labelView: null }); | |
accounts.push({ name: "Valerian Vast", money: 100, labelView: null }); | |
accounts.push({ name: "Archonicus Auriarch", money: 100, labelView: null }); | |
accounts.forEach(account => { | |
let row = document.body.appendChild(document.createElement("div")); | |
row.appendChild(document.createTextNode(account.name + ":")); | |
account.labelView = row.appendChild(document.createElement("span")); | |
account.labelView.textContent = account.money; | |
let payButton = row.appendChild(document.createElement("button")); | |
payButton.textContent = "Pay!"; | |
payButton.onclick = function() { | |
account.money = account.money + 10; | |
account.labelView.textContent = account.money; | |
}; | |
}); | |
let payEveryoneButton = document.body.appendChild(document.createElement("button")); | |
payEveryoneButton.textContent = "Pay Everyone!"; | |
payEveryoneButton.onclick = function() { | |
for (account of accounts) { | |
account.money = account.money + 10; | |
account.labelView.textContent = account.money; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment