Untitled
unknown
plain_text
a month ago
2.8 kB
6
Indexable
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>matematica e naspa!</title>
</head>
<body>
<h1>JOC DE MATEMATICA</h1>
<p id="intrebare">Apasa pe start!</p>
<Input id="raspuns" type="number" placeholder="Scrie raspunsul">
<button onclick="verificaRaspuns()">Verifica</button>
<button onclick="genereaza()">Start</button>
<p id="mesaj"></p>
<p>Scor: <span id="scor">0</span></p>
<p>Timp ramas: <span id="timp">10</span></p>
<script>
let numar1;
let numar2;
let rezultatCorect;
let timpRamas;
let cronometru;
let scor = 0;
function genereaza(){
clearInterval(cronometru);
numar1 = Math.floor(Math.random() * 10) +1;
numar2 = Math.floor(Math.random() * 10) +1;
rezultatCorect = numar1 + numar2;
document.getElementById("intrebare").innerText = "Cat face" + numar1 + "+" + numar2 + "?";
document.getElementById("raspuns").value = "";
document.getElementById("mesaj").innerText = "";
document.body.style.backgroundColor = "yellow";
timpRamas = 10;
document.getElementById("timp").value = timpRamas;
cronometru = setInterval(function(){
timpRamas--;
document.getElementById("timp").innerText = timpRamas;
if(timpRamas === 0){
clearInterval(cronometru);
document.getElementById("mesaj").innerText= "Esti un melc prost pentru ca timpul a expirat!";
document.body.style.backgroundColor ="red";
}
},1000);
}
function verificaRaspuns(){
let raspunsElev = Number(document.getElementById("raspuns").value);
clearInterval(cronometru);
if(raspunsElev === rezultatCorect){
scor++
document.getElementById("mesaj").innerText = "Corect!"
document.body.style.backgroundColor = "green";
}else{
scor=0;
document.getElementById("mesaj").innerText = "Incorect ba pro*tule!Raspunsul corect era " + rezultatCorect + "!";
document.body.style.backgroundColor = "red";
}
document.getElementById("scor").innerText = scor;
}
</script>
</body>
</html>
Editor is loading...
Leave a Comment