Hi people! I got some issues that I need help with. I'm new to JS so dont be hatin' I need a timer, that counts down from 20 seconds, everytime you get a correct answere you get another second added, each time you get the answere wrong, you get one second less.. Have a look at the code, and test it out, you'll understand <script type="text/javascript"> var tall1, tall2; var løsning; var førstegang = true; var svar; var resultat; var poeng = 0; var sekunder = 20 function startSpill() { if(førstegang) { førstegang = false; } else { lagLøsning(); sjekkSvar(); } tall1 = Math.floor(1 + Math.random() * 10); tall2 = Math.floor(1 + Math.random() * 10); start(); } function start() { document.getElementById("regnestykke").innerHTML = tall1 + " * " + tall2 + " = <input id='svar' type='text' /><input type='button' onclick='startSpill()'value='Svar' />"; } function lagLøsning() { løsning = tall1 * tall2; } function sjekkSvar() { svar = document.getElementById("svar").value; if(svar == løsning) { poeng++; document.getElementById("poeng").innerHTML = "Poeng:" + poeng; } else { poeng--; document.getElementById("poeng").innerHTML = "Poeng:" + poeng; } } function nedtelling() { if(førstegang) { førstegang = false; } else { startNedtelling() } } function startNedtelling() { sekunder --; setInterval("sekunder",1000); document.getElementById("klokke").innerHTML = "Tid:" + sekunder; } </script> </head> <body> <h1>Mattegeni!</h1> <div id="regnestykke"> <label> Trykk på start for begynne! <input type="button" value="Start" onclick="startSpill()" /> </label> </div> <!-- regnestykke --> <div id="poeng"> </div> <div id="klokke"> </div> </body> </html> Thanks alot for any suggestions and help -peace
Hi setInterval takes a function call as the first param, so it should be something like setInterval("startNedtelling()",1000); it's pretty difficult to follow your code (my norwegian is a bit rusty ) let me know if it works kind regards, John