This repository has been archived on 2024-02-11. You can view files and clone it, but cannot push or open issues or pull requests.
sitio/timer.html

57 lines
1.4 KiB
HTML
Raw Permalink Normal View History

2022-02-03 04:18:15 +00:00
<!doctype html>
<meta charset=utf-8>
<meta name=viewport content='width=device-width, initial-scale=1.0'>
<link rel=stylesheet href=https://nulo.in/drip.css>
<title>Timer de guita</title>
<style>
body {
display: flex;
min-height: 100vh;
justify-content: center;
align-items: center;
padding: 0;
}
main {
text-align: center;
padding: 0 1em;
}
input {
width: 5em;
}
</style>
<main>
<h1>Guita: <span id="guita" data-guita="0">$ 0.00</span></h1>
<div>
<label for="por-hora">Guita por hora por persona:</label>
<input value="0" type="number" id="por-hora" />
</div>
<div>
<label for="personas">Cantidad de personas:</label>
<input value="1" type="number" id="personas" />
</div>
<button>Empezar</button>
</main>
<script>
const guitaEl = document.querySelector('#guita')
const porHoraEl = document.querySelector('#por-hora')
const personasEl = document.querySelector('#personas')
const buttonEl = document.querySelector('button')
let interval = null
buttonEl.addEventListener('click', event => {
if (interval) {
clearInterval(interval)
buttonEl.textContent = 'Empezar'
} else {
interval = setInterval(() => {
guitaEl.dataset.guita = parseFloat(guitaEl.dataset.guita) + (porHoraEl.value / 60 / 60) * personasEl.value
guitaEl.textContent = `$ ${parseFloat(guitaEl.dataset.guita).toFixed(2)}`
}, 1000)
buttonEl.textContent = 'Parar'
}
})
</script>