<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>A Simple Quiz</title>
<link rel="stylesheet" href="styles.css">
<script>
var q = ["How many days are in an year?", "How many days does february have in a leap year?","How many hours equals to 1 day?"];
var a = [365, 29, 24];
var fd =["Incorrect! Its 365", "Incorrect! It has 29 days", "Incorrect! It has 24 hours"];
function scores() {
document.getElementById('output').innerHTML = askquestion();
}
function askquestion() {
var score=0;
for(var i=0; i<3; i++) {
var question=prompt(q[i]);
if (question==a[i]){
alert("Correct Answer");
score=score +1;
}
else {
alert(fd[i]);
}
}
return score
}
</script>
</head>
<body>
<h1> A Simple Quiz </h2>
<hr>
<script> scores()</script>
<h2> The score is: </h2> <output id="finalscore"></output>
<hr>
</body>
</html>
Above is my code. I'm trying to print the score next to "the score is: ". But I can't figure out a way! I know we can't use print statement or anything. But I was hoping there is a way out. Thanks in advance!