0

I am trying to an online test sample applicatio with java script & I am facing some problem with the increment value of correct variable .The result of the increment value showing some strange value. If anyone can help me i can give y whole demo code

function checkAnswer(result,id,corrected)
   {
    var value;
      var choice=document.getElementsByName('choice');
      for(var i=0;i<choice.length;i++)                               //checkAnswer() function e problem ache 
      {
        if(choice[i].checked)
        {
           value=choice[i].value;
        }
      }  
        if(value===result)
        {
          corrected++;
        }
        if(id==last)
      {
        databox.innerHTML='<h3> You have given '+corrected+' correct answers out of '+last;
      }

   }

2 Answers2

0

You can either ...

  • Change if(value===result) into if(value==result)
  • or provide the result parameter as a string: checkAnswer('1',1,0)instead of checkAnser(1,1,0).

Running code: https://jsfiddle.net/5y41y4v6/1/

If you are curious why, check the Difference between == and === in JavaScript

Community
  • 1
  • 1
Marc Compte
  • 4,579
  • 2
  • 16
  • 22
-1

I solved this problem my putting:

-> Change if(value===result) into if(value==result)

If you are curious why, check the Difference between == and === in JavaScript