-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
82 lines (55 loc) · 2.26 KB
/
script.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
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
(function() {
var score = 0;
var Question = function(question, answer, correctAnswer) {
this.question = question;
this.answer = answer;
this.correctAnswer = correctAnswer;
}
Question.prototype.displayQuestion = function() {
console.log(this.question);
for (var i = 0; i < this.answer.length; i++) {
console.log(i + ': ' + this.answer[i]);
}
}
Question.prototype.promptAnswer = function() {
var promptWindow = prompt("Please, select the correct answer :)\nIf you want quit, write exit", '');
if (promptWindow === "exit") {
return console.log("=====================\n" + "******GAME OVER******" + "\n=====================");
}
if (+promptWindow === this.correctAnswer) {
console.log("Correct answer");
score++;
console.log("-------------------------------------\n" + "Your current score is: " + score + "\n-------------------------------------");
if (score < 3) {
nextQuestion();
} else {
console.log("=====================\n" + "*****YOU WIN!!*****" + "\n=====================");
}
} else {
console.log("Wrong answer, try again :)");
nextQuestion();
}
}
var q1 = new Question('В каком году создали ECMAScript?', ['1996', '1997', '1995'], 2);
var q2 = new Question('Как зовут автора этой игры?', ['Максимка',
'Андрюшечка',
'Юлечка'
], 1);
var q3 = new Question('Когда будете высылать оффер?', ['Ой, ты такой талантливый',
'Не испробовать тебе смузи, холоп',
'БОЖЕ, ВЫСЫЛАЕМ!!!111'
], 2);
var questions = [q1, q2, q3];
function nextQuestion() {
var n = Math.floor(Math.random() * questions.length);
questions[n].displayQuestion();
var promptCall = function() {
questions[n].promptAnswer();
}
setTimeout(promptCall, 150);
}
document.getElementById('button').addEventListener("click" ,function () {
score = 0;
nextQuestion();
})
}());