Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:44:21+00:00 2026-06-10T18:44:21+00:00

I am pretty sure I have missed something simple, but Score is not counting

  • 0

I am pretty sure I have missed something simple, but Score is not counting correctly based on whether the correct answer has been selected. Its a multiple choice quiz. The code was written by someone else, so trying to figure this out alone! Any ideas?


var Question = function(Text){
  this.Question = Text;
  this.Answers = [];
  this.addAnswer = function(Answer, Correct){
    if(typeof Correct == 'undefined') Correct = false;
    else Correct = Correct == true;
    this.Answers.push({"Answer":Answer, "Correct":Correct});
  };
  this.checkAnswer = function(Index){
    if(typeof this.Answers[Index] == 'undefined') return false;
    return this.Answers[Index].Correct;
  };
};


var Questions = [];
var q;
var Score = 0;
var CurrentQuestion = -1;

var nextQuestion = function()
{
  ++CurrentQuestion;

  if(typeof Questions[CurrentQuestion] == 'undefined') return false;
  var Question = Questions[CurrentQuestion];

  $('#QuestionIndex').html(Numbers[CurrentQuestion]);
  $('#QuestionsRemaining').html((Questions.length-CurrentQuestion-1));
  $('#Question').html(Question.Question);
  $('#Answers').html('');


  for(var t in Question.Answers)
  {
    i = t;
    t = Question.Answers[t];
    var Div = $('<div class="answer"></div>');
    $(Div).append('<span class="radioContainer"><input type="radio" name="Answer" id="answer_'+ i +'"></span> ');
    $(Div).append($('<label for="answer_' + i + '" />').html(t.Answer));
    $('#Answers').append(Div);
  }

  $("input[type='radio']").change(function(){
    $('.radioContainer').css('background-image', 'none');

    attr = $(this).attr('checked');
    if(typeof attr !== 'undefined' && attr !== false)
    {
   $(this).parent().css('background-image', 'url("http://dev.clickymedia.co.uk/fbart/wp-content/themes/artbook/img/tick.png")');
    }
  });

  return true;
}

//Returning false should stop the user from progressing to the next question.
var checkCurrentAnswer = function()
{
  if(typeof Questions[CurrentQuestion] == 'undefined') return false;
  var i = $('#Answers input:checked').parent().index();
  if(i < 0) return false;

  if(Questions[CurrentQuestion].checkAnswer(i) == true) Score++; 

  return true;
}

q = new Question("Which famous film star did Pop artist Andy Warhol make more portraits of than any other?");
q.addAnswer('Marilyn Monroe', true);
q.addAnswer('Sophia Loren');
q.addAnswer('Audrey Hepburn');
q.addAnswer('Doris Day');
Questions.push(q);

q = new Question("The Mona Lisa, Leonardo da Vinci's magnum opus, draws crowds into which famous European museum?");
q.addAnswer('The Mus&#233;e du Louvre, Paris', true);
q.addAnswer('The Tate Britain, London');
q.addAnswer('The National Gallery, Berlin');
q.addAnswer('The Uffizi Gallery, Florence');
Questions.push(q);

$(function(){
  nextQuestion();

  $('#nextQuestion').bind('click', function(){
    if(checkCurrentAnswer())
    {
      if(nextQuestion())
      {

      }else{ //End of examination! - Put your pens and pencils down.
        $('#QuestionBook .FinalLeft .Score').html(Score + '/' + Questions.length);

        $('#QuestionBook .FinalLeft .Message').html(Message);


        $('#QuestionBook .QuestionContainer, #QuestionBook .AnswersContainer').hide();
        $('#QuestionBook .FinalLeft, #QuestionBook .FinalRight').show();


      }
    }
  });
});

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:44:23+00:00Added an answer on June 10, 2026 at 6:44 pm

    Your checkCurrentAnswer function is calculating the wrong index. Specifically, this line:

    var i = $('#Answers input:checked').parent().index();

    Your HTML looks like this:

    <div id="Answers">
      <div class="answer">
        <span class="radioContainer"><input type="radio" /></span>
        <label for="answer_0">The Musée du Louvre, Paris</label>
      </div>
      <div class="answer">
        <span class="radioContainer"><input type="radio" /></span>
        <label for="answer_1">The Tate Britain, London</label>
      </div>
      ...
    </div>
    

    Thus, i will always be 0, since the parent of the radio input is always a span, which is always the first child (index 0) of answer. You should count the index of the div with class answer instead.

    To fix, it’s simple, instead of using parent(), use closest(".answer"):

    var i = $('#Answers input:checked').closest(".answer").index();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty sure that I have just missed something very obvious but to
I'm pretty sure it's easy but I can't seem to find it. I have
Hi i have a problems with simplexml_load_file, i'm not pretty sure how to do
I have a pretty crappy book so I am not sure for their reasoning
Pretty sure there is an easy answer to this, but just can't find the
I am pretty sure I have seen this before, but I haven't found out
I'm not sure how to describe this best. But I have a problem understanding
I have what I'm pretty sure is a bug in the optimizer in Visual
I have received a design which i am pretty sure is a flash website
I have this annoying problem, that Im pretty sure happens to all of you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.