Skip to content

Instantly share code, notes, and snippets.

@Verdagon
Created April 7, 2022 01:10
Show Gist options
  • Save Verdagon/e579f89d4aac7ecd05b0514939686f4c to your computer and use it in GitHub Desktop.
Save Verdagon/e579f89d4aac7ecd05b0514939686f4c to your computer and use it in GitHub Desktop.
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