-
Notifications
You must be signed in to change notification settings - Fork 0
/
app(simplest).js
executable file
·47 lines (40 loc) · 1.08 KB
/
app(simplest).js
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
(function() {
function Question(question, answers, correct) {
this.question = question;
this.answers = answers;
this.correct = correct;
}
Question.prototype.displayQuestion = function() {
console.log(this.question);
for (var i = 0; i < this.answers.length; i++) {
console.log(i + ": " + this.answers[i]);
}
};
Question.prototype.checkAnswer = function(ans) {
if (ans === this.correct) {
console.log("Correct Answer.");
} else {
console.log("Wrong Answer. Please try again.");
}
};
var q1 = new Question(
"Is Js the coolest programming lang?",
["yes", "no"],
0
);
var q2 = new Question(
"Whats the name of this courses?",
["John", "Marry", "Jonas"],
1
);
var q3 = new Question(
"What does best describe coding?",
["boring", "hard", "Tedios", "fun"],
3
);
var questions = [q1, q2, q3];
var n = Math.floor(Math.random() * questions.length);
questions[n].displayQuestion();
var answer = parseInt(prompt("Please select the correct answer !"));
questions[n].checkAnswer(answer);
})();