Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question.prototype.displayRandomQuestion = function() // function to loop through all the questions and answers
- {
- console.log(this.question);
- for(var i = 0; i < this.answer.length; i++)
- {
- console.log(i + " : " + this.answer[i]);
- }
- }
- Question.prototype.checkAnswer = function(ans)
- {
- if(ans === this.correct)
- {
- console.log('correct output!!');
- }
- else
- {
- console.log('Wrong answer !!');
- }
- }
- // questions to be logged on the console arg(1), possible outcomes arg(2), correct ans arg(3)
- var ques1 = new Question('Is Mclaren Speedtail better than a Bugatti Chiron ??', ['yes', 'no'], 0);
- var ques2 = new Question('Which is the best Hypercar Brand ?', ['Porsche', 'Ferrari', 'Mclaren'], 2);
- var ques3 = new Question('What are the best Engine Types ?', ['Naturally Aspirated', 'Hybrid', 'Turbo-charged', 'Supercharged'], 1);
- var questions = [ques1, ques2, ques3];
- var getRandom = Math.floor(Math.random() * questions.length); // generating random question on the console
- questions[getRandom].displayRandomQuestion();
- var answer = parseInt (prompt('Please select the correct answer !!'));
- questions[getRandom].checkAnswer(answer);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement