-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
83 lines (76 loc) · 2.33 KB
/
javascript.js
File metadata and controls
83 lines (76 loc) · 2.33 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var playing=false;
var action;
var timecounter=60;
var score;
var correctAnswer;
var correctOption;
document.getElementById("startreset").onclick= function(){
if(playing==false)
{score=0;
document.getElementById("startreset").innerHTML="Reset Game";
document.getElementById("gameover").style.display = "none";
document.getElementById("timeremaining").style.display = "block";
document.getElementById("score").innerHTML = score;
playing=true;
questions();
startcounting();
}
else
location.reload();
}
function startcounting(){
action=setInterval(function(){
document.getElementById("counter").innerHTML = timecounter;
timecounter-=1;
if(timecounter==-1)
{clearInterval(action);
document.getElementById("gameover").style.display ="block";
document.getElementById("scorevalue").innerHTML = score;
playing=false;
timecounter=60;
document.getElementById("timeremaining").style.display = "none";
document.getElementById("startreset").innerHTML = "Start Game";
}
},500)
}
function questions(){
var x=1+ Math.round(9*Math.random());
var y=1+ Math.round(9*Math.random());
correctAnswer=x*y;
document.getElementById("display").innerHTML= x + "*" +y;
correctOption = 1 + Math.round(3*Math.random());
document.getElementById("box" + correctOption).innerHTML = correctAnswer;
for(i=1;i<5;i++)
{ var wronganswer=(1+Math.round(9*Math.random()))*(1+Math.round(9*Math.random()))
if(i!=correctOption)
{ if(wronganswer==correctAnswer)
wronganswer=wronganswer+1;
document.getElementById("box"+i).innerHTML=wronganswer;
}
}
}
for(i=1;i<5;i++)
{document.getElementById("box"+i).onclick =
function(){
if(playing==true)
{ if(this.innerHTML==correctAnswer)
{ score++;
document.getElementById("score").innerHTML = score;
document.getElementById("correct").style.display="block";
setTimeout(function(){
document.getElementById("correct").style.display="none";
},1000);
questions();
}
else
{document.getElementById("wrong").style.display="block";
setTimeout(function(){
document.getElementById("wrong").style.display="none";
},1000)
}
}
}
}
$(function(){
$("*").css("font-size",'30px');
});