Webchance/static/app.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

const LOOSE_MESSAGE = "im sorry, but you lost"
const WIN_MESSAGE = "congrats, you win"
2024-09-26 16:43:51 +02:00
2024-09-26 17:46:12 +02:00
async function calcChanche() {
const name = document.getElementById("name").value
2024-09-26 16:43:51 +02:00
const chance = document.getElementById("Chance").value
const mult = document.getElementById("Multiplicator").value
const url = "/random?chance=" + chance + "&multiplicator=" + mult + "&name=" + name;
2024-09-26 16:43:51 +02:00
try {
const response = await fetch(url);
const content = await response.text()
console.log(content);
if (content == "true") {
document.getElementById("won").innerText = WIN_MESSAGE
}
else {
document.getElementById("won").innerText = LOOSE_MESSAGE
}
getWinners()
2024-09-26 17:46:12 +02:00
} catch (error) {
console.error(error.message);
2024-09-26 17:46:12 +02:00
}
}
async function getWinners() {
const url = "/winners"
try {
const response = await fetch(url);
const content = await response.text()
2024-09-26 17:46:12 +02:00
document.getElementById("winners").innerText = content
2024-09-26 16:43:51 +02:00
} catch (error) {
console.error(error.message);
2024-09-26 16:43:51 +02:00
}
}