-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (30 loc) · 1.16 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let myinput = document.getElementById("my-input")
function stepper(btn){
let id = btn.getAttribute("id");
let val = myinput.getAttribute("value");
let total = (id == "diminuir") ? (parseInt(val)-1): (parseInt(val)+1);
myinput.setAttribute("value", total);
}
function rolar(){
let rolagem = Math.floor(Math.random() * 20 +1);
let valor = myinput.getAttribute("value");
spin()
document.getElementById("result").innerHTML = rolagem;
document.getElementById("span").innerHTML = parseInt(valor)+rolagem;
if (rolagem === 20){
document.getElementById("result").style.color = "var(--green)";
document.getElementById("body").style.backgroundColor = "var(--dark-green)";
}
else if(rolagem === 1){
document.getElementById("result").style.color = "var(--red)";
document.getElementById("body").style.backgroundColor = "var(--dark-red)";
}
else{
document.getElementById("result").style.color = "black";
document.getElementById("body").style.backgroundColor = "var(--black)";
}
}
function spin(){
dado.classList.add("spin");
setTimeout(function(){dado.classList.remove("spin");}, 500);
}