Skip to content

Instantly share code, notes, and snippets.

@CephandriusMaxtori
Created January 24, 2025 15:42
Show Gist options
  • Select an option

  • Save CephandriusMaxtori/f5c57f15db68976e2fdcff96dadc2cf1 to your computer and use it in GitHub Desktop.

Select an option

Save CephandriusMaxtori/f5c57f15db68976e2fdcff96dadc2cf1 to your computer and use it in GitHub Desktop.
Untitled
<!DOCTYPE html>
<html>
<head>
<title>Simple Token Tracker</title>
<style>
body {
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
padding: 20px;
}
ul {
list-style: none;
padding: 0;
}
li {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding: 10px 15px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
padding: 5px 10px;
border: none;
border-radius: 3px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>Token Tracker</h1>
<div>
<label for="person">Person:</label>
<input type="text" id="person" placeholder="Enter Person's Name">
<button onclick="addPerson()">Add Person</button>
</div>
<ul id="peopleList"></ul>
</div>
<script>
let people = [];
function addPerson() {
const personName = document.getElementById("person").value;
if (personName === "") return;
people.push({ name: personName, tokens: 0 });
displayPeople();
document.getElementById("person").value = "";
}
function displayPeople() {
const peopleList = document.getElementById("peopleList");
peopleList.innerHTML = "";
people.forEach((person, index) => {
const listItem = document.createElement("li");
listItem.textContent = `${person.name}: ${person.tokens} tokens`;
const giveButton = document.createElement("button");
giveButton.textContent = "+";
giveButton.addEventListener("click", () => {
if (index >= 0 && index < people.length) {
people[index].tokens++;
}
displayPeople();
});
listItem.appendChild(giveButton);
const takeButton = document.createElement("button");
takeButton.textContent = "-";
takeButton.addEventListener("click", () => {
if (index >= 0 && index < people.length && people[index].tokens > 0) {
people[index].tokens--;
}
displayPeople();
});
listItem.appendChild(takeButton);
const removeButton = document.createElement("button");
removeButton.textContent = "X";
removeButton.addEventListener("click", () => {
people.splice(index, 1);
displayPeople();
});
listItem.appendChild(removeButton);
peopleList.appendChild(listItem);
});
}
displayPeople();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment