Repository navigation
Expand file tree
/
Copy pathquiz.html
More file actions
85 lines (54 loc) · 1.69 KB
/
Copy pathquiz.html
File metadata and controls
85 lines (54 loc) · 1.69 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
<html>
<head>
<script>
function Question(qno,qdesc,o1,o2,o3,o4,ans){
this.qno=qno;
this.qdesc=qdesc;
this.o1=o1;
this.o2=o2;
this.o3=o3;
this.o4=o4;
this.ans = ans;
}
var questions = new Array();
questions[0] = new Question(1,"Where is T-hub ?","Banglore","Hyderabad","Delhi","Gurgoan",2);
questions[1] = new Question(2,"Hyderabad is located in ?","Telangana","Andhra pradesh","Tamilnadu","Kerala",1);
questions[2] = new Question(3,"What is JQuery?","Html component ","Web application","Programming laungage","All of the above",3);
function displayQuestions(){
var text = "";
for(i=0;i<questions.length;i++){
text = text + questions[i].qdesc+" <br>";
text = text + "<input type='radio' name='"+questions[i].qno+"' value='1'>"+questions[i].o1+" <br>";
text = text + "<input type='radio' name='"+questions[i].qno+"' value='2'>"+questions[i].o2+" <br>";
text = text + "<input type='radio' name='"+questions[i].qno+"' value='3'>"+questions[i].o3+" <br>";
text = text + "<input type='radio' name='"+questions[i].qno+"' value='4'>"+questions[i].o4+" <br><br>";
}
text = text + "<button onclick='calculateScore()'> SUBMIT </button>"
document.getElementById("quiz").innerHTML = text;
}
function calculateScore(){
var count = 0;
var radioBoxes = document.getElementsByTagName("input");
for(i=0;i<questions.length;i++){
for(j=0;j<radioBoxes.length;j++){
if(radioBoxes[j].type == 'radio'){
if(radioBoxes[j].name == questions[i].qno){
if(radioBoxes[j].checked == true){
if(radioBoxes[j].value == questions[i].ans){
count++;
}
}
}
}
}
}
alert(count+" / "+questions.length);
}
</script>
</head>
<body>
<div id="quiz">
<button onclick="displayQuestions()"> Take Test </button>
</div>
</body>
</html>