Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 880fad5

Browse files
author
Samane
authored
Add files via upload
1 parent 485ed4a commit 880fad5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎Challenge6/app.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function () {
2+
var Question = function (question, answers, correct) {
3+
this.question = question;
4+
this.answers = answers;
5+
this.correct = correct;
6+
}
7+
8+
Question.prototype.display = function () {
9+
console.log(this.question);
10+
for (var i = 0; i < this.answers.length; i++)
11+
console.log((i + 1) + '. ' + this.answers[i]);
12+
}
13+
14+
Question.prototype.checkAnswer = function (answer) {
15+
if (answer === this.correct)
16+
console.log('Correct!');
17+
else
18+
console.log('incorrect. Try again! :)');
19+
}
20+
21+
var question_1 = new Question('Is JavaScript the coolest programming language in the world?', ['Yes', 'No'], 1);
22+
var question_2 = new Question('How many days are 1 week?', ['5days', '9days', '7days', '11days'], 3);
23+
var arr = [question_1, question_2];
24+
var num = Math.floor(Math.random() * arr.length);
25+
arr[num].display();
26+
var answer = parseInt(prompt('Enter the number of the correct answer'));
27+
arr[num].checkAnswer(answer);
28+
29+
})();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /