Webchance/static/app.js
Gian Breitenstein 2f7d1a03cb
All checks were successful
Release / publish (push) Successful in 57s
Moved css to own file, changed parameters to look like labels. Costumized output text.
2024-09-26 21:47:02 +02:00

37 lines
1.1 KiB
JavaScript

const LOOSE_MESSAGE = "im sorry, but you lost"
const WIN_MESSAGE = "congrats, you win"
async function calcChanche() {
const name = document.getElementById("name").value
const chance = document.getElementById("Chance").value
const mult = document.getElementById("Multiplicator").value
const url = "/random?chance=" + chance + "&multiplicator=" + mult + "&name=" + name;
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()
} catch (error) {
console.error(error.message);
}
}
async function getWinners() {
const url = "/winners"
try {
const response = await fetch(url);
const content = await response.text()
document.getElementById("winners").innerText = content
} catch (error) {
console.error(error.message);
}
}