-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
139 lines (133 loc) · 4.29 KB
/
Copy pathscript.js
File metadata and controls
139 lines (133 loc) · 4.29 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
let timeInterval=null;
let timeLeft=30;
let score=0;
let Qindex=0;
let questions = [{
question : "Who holds the record for the most centuries in International Cricket",
options : ["Virat Kohli","Ricky Pointing","Sachin Tendulkar","Rohit Sharma"],
correct : "Sachin Tendulkar"
},
{
question : "Who holds the record for the fastest century in ODIs?",
options : ["AB de Villiers","Virat Kohli","Rohit Sharma","Chris Gayle"],
correct : "AB de Villiers"
},
{
question : "Which bowler has taken the most wickets in Test cricket?",
options : ["James Anderson","Shane Warne","Muttiah Muralitharan","Anil Kumble"],
correct : "Muttiah Muralitharan"
},
{
question : "Who is the only player to score a century and take a five-wicket haul in the same match on Test debut?",
options: ["Kapil Dev","Ian Botham","Bruce Taylor","Jacques Kallis"],
correct : "Bruce Taylor"
},
{
question : "Which cricketer was involved in the famous `Mankading` dismissal of Jos Buttler in IPL 2019?",
options: ["Ravichandran Ashwin","Ravindra Jadeja","Sunil Narine","Yuzvendra Chahal"],
correct : "Ravichandran Ashwin"
},
{
question : "Who was the first bowler to take a hat-trick in T20 Internationals?",
options: ["Jasprit Bumrah","Brett Lee","Lasith Malinga","Dale Steyn"],
correct : "Brett Lee"
},
{
question : "Who is the only Indian cricketer to have played 100+ international matches in all three formats?",
options: ["Rohit Sharma","MS Dhoni","Sachin Tendulkar","Virat Kohli"],
correct : "Virat Kohli"
},
{
question : "Which ground hosted the first-ever day-night Test match?",
options: ["Eden Gardens","Adelaide Oval","Dubai International Stadium","Lord's Cricket Ground"],
correct : "Adelaide Oval"
},
{
question : "Who was the first cricketer to hit 6 sixes in an over in international cricket?",
options: ["Kieron Pollard","Yuvraj Singh","Herschelle Gibbs","Tim David"],
correct : "Herschelle Gibbs"
},
{
question : "Which of the given below is NOT a nickname given to The Legendary MS Dhoni by his fans",
options: ["Thala","Dhobi","Captain Cool","DRS(Dhoni Review System)"],
correct : "Dhobi"
}];
function loadQuestion()
{
document.getElementById("restart").style.display="none";
timeLeft=30;
let ques=document.getElementById("Question");
ques.textContent=questions[Qindex].question;
let opt=document.getElementById("options");
opt.innerHTML="";
questions[Qindex].options.forEach(function(option){
let btn=document.createElement("button");
btn.textContent=option;
opt.appendChild(btn);
btn.onclick= function() {checkAnswer(btn.textContent)};
})
startTimer();
}
function checkAnswer(answer)
{
clearInterval(timeInterval);
if(answer===questions[Qindex].correct)
score++;
document.getElementById("options").querySelectorAll("button").forEach(function(btn){
if(btn.textContent===questions[Qindex].correct)
{
btn.style.background="green";
btn.style.color="white";
}
else
{
btn.style.background="red";
btn.style.color="white";
}
btn.disabled=true;
})
if(Qindex<10)
{
document.getElementById("next-btn").style.display="block";
document.getElementById("next-btn").onclick = function () {nextone()};
}
}
function nextone()
{
Qindex++;
if(Qindex>=10)
{
document.getElementById("Question").innerHTML="";
document.getElementById("options").innerHTML="";
document.getElementById("next-btn").style.display="none";
document.getElementById("result").style.display="block";
document.getElementById("result").textContent=`${score}/10`;
document.getElementById("restart").style.display="block";
}
else
{
document.getElementById("next-btn").style.display="none";
loadQuestion();
}
}
function startTimer()
{
timeInterval=setInterval(function() {
timeLeft--;
document.getElementById("timer").textContent=timeLeft;
if(timeLeft<=0)
{
clearInterval(timeInterval);
nextone();
}
},1000);
}
function restart()
{
timeInterval=null;
timeLeft=30;
score=0;
Qindex=0;
loadQuestion();
}
loadQuestion();