-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (33 loc) · 1.13 KB
/
script.js
File metadata and controls
38 lines (33 loc) · 1.13 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
function submitAnswers() {
var total = 5;
var score = 0;
//Get User Input
var q1 = document.forms["quiz-form"]["q1"].value;
var q2 = document.forms["quiz-form"]["q2"].value;
var q3 = document.forms["quiz-form"]["q3"].value;
var q4 = document.forms["quiz-form"]["q4"].value;
var q5 = document.forms["quiz-form"]["q5"].value;
//Validation
for (var i = 1; i <= total; i++) {
if (eval("q"+i) == null || eval("q"+i) == "") {
alert("You missed question " + i);
return false;
}
}
//Set Correct Answers
var answers = ["b", "a", "d", "b", "d"];
//Check Answers
for (var i = 1; i <= total; i++) {
if (eval("q"+i) == answers[i - 1]) {
score++;
}
}
//Display Results
var results = document.getElementById("results");
results.innerHTML = "<h3>You scored <span>" + score + "</span> out of <span>" + total + "</span>.</h3>"
alert("You scored " + score + " out of " + total + ".");
if(score < 4) {
alert("You might want to brush up on your JS fundamentals.");
}
return false;
}