Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Quiz Issue

Quiz Issue

Scheduled Pinned Locked Moved JavaScript
javascriptquestionhtmlcssxml
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shobhit Rathour
    wrote on last edited by
    #1

    Hello we do develop a quiz also have code but we want just quiz check which user click on mcq answer

    function Quiz(questions) {
    this.score = 0;
    this.questions = questions;
    this.questionIndex = 0;

    }

    Quiz.prototype.getQuestionIndex = function() {
    return this.questions[this.questionIndex];
    }

    Quiz.prototype.guess = function(answer) {
    if(this.getQuestionIndex().isCorrectAnswer(answer)) {

        this.score++;
    }
    
    this.questionIndex++;
    

    }

    Quiz.prototype.isEnded = function() {
    return this.questionIndex === this.questions.length;
    }

    function Question(text, choices, answer) {
    this.text = text;
    this.choices = choices;
    this.answer = answer;
    }

    Question.prototype.isCorrectAnswer = function(choice) {
    return this.answer === choice;

    }

    function populate() {
    if(quiz.isEnded()) {
    showScores();
    }
    else {
    // show question
    var element = document.getElementById("question");
    element.innerHTML = quiz.getQuestionIndex().text;

        // show options
        var choices = quiz.getQuestionIndex().choices;
        for(var i = 0; i < choices.length; i++) {
            var element = document.getElementById("choice" + i);
            element.innerHTML = choices\[i\];
            guess("btn" + i, choices\[i\]);
        }
    
        showProgress();
    }
    

    };

    function guess(id, guess) {
    var button = document.getElementById(id);
    button.onclick = function() {
    quiz.guess(guess);
    populate();
    }
    };

    function showProgress() {
    var currentQuestionNumber = quiz.questionIndex + 1;
    var element = document.getElementById("progress");
    element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length;
    };

    function showScores() {
    var gameOverHTML = "<h1>Result</h1>";
    gameOverHTML += "<h2 id='score'> Your scores: " + quiz.score + "</h2>";
    var element = document.getElementById("quiz");
    element.innerHTML = gameOverHTML;
    };

    // create questions here
    var questions = [
    new Question("शरीर से पसीना सबसे अधिक कब निकलता है", ["जब तापक्रम अधिक और हवा सुख हो", "जब तापक्रम अधिक और हवा आर्द्र हो","जब तापक्रम कम और हवा आर्द्र हो", "जब तापक्रम कम और हवा सुखी हो"], "जब तापक्रम अधिक और हवा आर्द्र हो"),
    new Question("Which language is used for styling web pages?", ["HTML", "JQuery", "CSS", "XML"], "CSS"),
    new Question("Which is not a JavaScript Framework?", ["Pytho

    A 1 Reply Last reply
    0
    • S Shobhit Rathour

      Hello we do develop a quiz also have code but we want just quiz check which user click on mcq answer

      function Quiz(questions) {
      this.score = 0;
      this.questions = questions;
      this.questionIndex = 0;

      }

      Quiz.prototype.getQuestionIndex = function() {
      return this.questions[this.questionIndex];
      }

      Quiz.prototype.guess = function(answer) {
      if(this.getQuestionIndex().isCorrectAnswer(answer)) {

          this.score++;
      }
      
      this.questionIndex++;
      

      }

      Quiz.prototype.isEnded = function() {
      return this.questionIndex === this.questions.length;
      }

      function Question(text, choices, answer) {
      this.text = text;
      this.choices = choices;
      this.answer = answer;
      }

      Question.prototype.isCorrectAnswer = function(choice) {
      return this.answer === choice;

      }

      function populate() {
      if(quiz.isEnded()) {
      showScores();
      }
      else {
      // show question
      var element = document.getElementById("question");
      element.innerHTML = quiz.getQuestionIndex().text;

          // show options
          var choices = quiz.getQuestionIndex().choices;
          for(var i = 0; i < choices.length; i++) {
              var element = document.getElementById("choice" + i);
              element.innerHTML = choices\[i\];
              guess("btn" + i, choices\[i\]);
          }
      
          showProgress();
      }
      

      };

      function guess(id, guess) {
      var button = document.getElementById(id);
      button.onclick = function() {
      quiz.guess(guess);
      populate();
      }
      };

      function showProgress() {
      var currentQuestionNumber = quiz.questionIndex + 1;
      var element = document.getElementById("progress");
      element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length;
      };

      function showScores() {
      var gameOverHTML = "<h1>Result</h1>";
      gameOverHTML += "<h2 id='score'> Your scores: " + quiz.score + "</h2>";
      var element = document.getElementById("quiz");
      element.innerHTML = gameOverHTML;
      };

      // create questions here
      var questions = [
      new Question("शरीर से पसीना सबसे अधिक कब निकलता है", ["जब तापक्रम अधिक और हवा सुख हो", "जब तापक्रम अधिक और हवा आर्द्र हो","जब तापक्रम कम और हवा आर्द्र हो", "जब तापक्रम कम और हवा सुखी हो"], "जब तापक्रम अधिक और हवा आर्द्र हो"),
      new Question("Which language is used for styling web pages?", ["HTML", "JQuery", "CSS", "XML"], "CSS"),
      new Question("Which is not a JavaScript Framework?", ["Pytho

      A Offline
      A Offline
      Afzaal Ahmad Zeeshan
      wrote on last edited by
      #2

      Quote:

      which user

      That needs you to know which user opened the form, which needs you to handle this request from a web server and authenticate the users before showing the form to them. That answer requests a server-side answer, and it depends on which language/framework you are using to build that.

      The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups