Professional Documents
Culture Documents
WP Assgn 1
WP Assgn 1
WP Assgn 1
Web Programming
Assignment - 1
Submitted by:
<head>
<meta charset="UTF-8">
<title>Quiz</title>
</head>
<body>
<div class="grid">
<div id="quiz">
<p id="question"></p>
<div class="buttons">
</div>
<footer>
</footer>
</div>
</div>
</div>
<script src="questions.js"></script>
</body>
</html>
1
CSS code:-
body{
background-color: #f7efef;
.grid{
width: 600px;
height: 500px;
margin: 0 auto;
.grid h1{
font-family: "sans-serif";
background-color: #252f7c;
font-size: 60px;
text-align: center;
color: #f7f1f1;
#score{
color: #021606;
text-align: center;
font-size: 30px;
.grid #question {
font-family: "monospace";
font-size: 30px;
color: #0a344b;
.buttons{
margin-top: 30px;
2
}
background-color: #460948;
width: 250px;
font-size: 20px;
cursor: pointer;
background-color: #634bba;
outline: 0;
#progress{
color: #312f2f;
font-size: 18px;
3
JAVASCRIPT code:-
function Quiz(questions) {
this.score = 0;
this.questions = questions;
this.questionIndex = 0;
Quiz.prototype.getQuestionIndex = function() {
return this.questions[this.questionIndex];
Quiz.prototype.guess = function(answer) {
if(this.getQuestionIndex().isCorrectAnswer(answer)) {
this.score++;
this.questionIndex++;
Quiz.prototype.isEnded = function() {
this.text = text;
this.choices = choices;
this.answer = answer;
Question.prototype.isCorrectAnswer = function(choice) {
4
function populate() {
if(quiz.isEnded()) {
showScores();
else {
// show question
element.innerHTML = quiz.getQuestionIndex().text;
// show options
element.innerHTML = choices[i];
guess("btn" + i, choices[i]);
showProgress();
};
button.onclick = function() {
quiz.guess(guess);
populate();
};
function showProgress() {
5
};
function showScores() {
gameOverHTML += "<h2 id='score'> You scored: " + quiz.score + " out of 5</h2>";
element.innerHTML = gameOverHTML;
};
function refreshPage(){
window.location.reload();
var questions = [
new Question("Who was the 1st ODI captain for India?", ["(a). Ajit Wadekar", "(b). Bishen Singh Bedi","(c).
Nawab Pataudi", "(d). Vinoo Mankad"], "(a). Ajit Wadekar"),
new Question("Where did India play its 1st one day international match?", ["(a). Lords", "(b). Headingley",
"(c). Tauntone", "(d). The Oval"], "(b). Headingley"),
new Question("India won its first Olympic hockey gold in...?", ["(a). 1928", "(b). 1932","(c). 1936", "(d).
1948"], "(a). 1928"),
new Question("Who won the 1993 King of the Ring?", ["(a). Owen Hart", "(b). Bret Hart", "(c). Edge", "(d).
Mabel"], "(b). Bret Hart"),
new Question("What is the name of the person that controls a football match?", ["(a).A referee", "(b). An
umpire", "(c). A spectator", "(d). A goalkeeper"], "(a). A referee")
];
// create quiz
// display quiz
populate();
6
OUTPUT:-