Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Question = function ( question, answers, right){
- this.question = question;
- this.answers = answers;
- this.right = right;
- }
- var q1 = new Question ('* What is the best programming language?' ,
- ['Java', 'JavaScript', 'Python'],
- 1);
- var q2 = new Question('* What is the best way to manage it',
- ['Study', 'Practice', 'Both'],
- 2);
- var q3 = new Question('* Do you think you will be a programmer one day?',
- ['YESSSS', 'Maybe', 'Unfortunately no'],
- 0);
- var q4 = new Question('* How long will it take to be a programmer?',
- ['Don\'t know', '6 months', 'Yeaaars'],
- 1);
- 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.checkIfCorrect = function(ans, comeBack){
- var po;
- if (ans === this.right){
- console.log('Correct answer! Good Job!');
- po = comeBack(true);
- } else {
- console.log('Sorry not corret. Try again :)');
- po = comeBack(false);
- }
- // this.displayPoints(po);
- }
- //Question.prototype.displayPoints = function(points){
- // console.log('Your score is ' + points +'!');
- // console.log('*^*^*^*^**^*^*');
- //}
- function points(){
- var po = 0;
- return function(right){
- if(right){
- po++;
- console.log('Your score is 1 point more! Now it\'s ' + po); // I added this part.
- console.log('*^*^*^*^*^*^*'); // also this.
- } else {
- console.log('Your score is still ' + po + '.'); // and this.
- console.log('*^*^*^*^*^*^*'); // and this :)
- }
- return po;
- }
- }
- var keepPoints = points();
- var questions = [q1, q2, q3, q4];
- function nextQuestion(){
- var n = Math.floor(Math.random() * questions.length);
- questions[n].displayQuestion();
- var answer = prompt('Please enter the your answer: ');
- if (answer !== 'exit'){
- questions[n].checkIfCorrect(parseInt(answer
- ), keepPoints);
- nextQuestion();
- }
- }
- nextQuestion();
Add Comment
Please, Sign In to add comment