title: Adding up score in matching game java script
body: <p>I am quite new to java script so please be patient with me:) So I am making a matching game in java script (matching animal prints with their names) and even if I click on the correct answer, a score is never added, therefore you always lose.</p>
  
  <p>How can I correct this problem? </p>
  
  <p>Here is my code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function randSort (a,b) {
    return Math.random() - 0.5;
  }
  
  var questions = [
    {
      text: " What animal is this?", 
      img: "AnimalPrints/1.jpg", 
      answers: ["Cheetah", "Tiger", "Ladybird"], 
      ans: "A"
    },
    {
      text: " What animal is this one?", 
      img: "AnimalPrints/2.jpg", 
      answers: ["Elephant", "Giraffe", "Snake"], 
      ans: "B"
    },
    {
      text: "What animal is this one please?", 
      img: "AnimalPrints/3.jpg", 
      answers: ["Bumblebee", "Tiger", "Lady bird"], 
      ans: "Bumblebee"
    }
  ];
  
  var correctCount = 0;
  var currentQ = 0;
  
  
  function select(nr) {
    if (nr == questions[currentQ].ans)
    {
      correctCount++;
      document.getElementById('display').innerHTML= "You win"
    }
    else
    {
      document.getElementById('display').innerHTML= "You lose"
    }
    document.getElementById('display').innerHTML += "&lt;p&gt;Score: "+ correctCount;
  
    // if its the last one
    nextQ();
  
  }   
  
  function showQ() {
    document.getElementById('questionText').innerHTML = questions[currentQ].text;
    document.getElementById('animalPrint').src = questions[currentQ].img;
    newhtml = "";
    for (var i = 0; i&lt; questions[currentQ].answers.length; i++)
    {
      newhtml+= "&lt;button onclick = 'select(" + i + ")'&gt;"+ questions[currentQ].answers[i] + "&lt;/button&gt;";
    }
    document.getElementById('alloptions').innerHTML = newhtml;
  }
  
  
  function nextQ(){
    if (currentQ &lt; questions.length-1)
    {   
      currentQ++;
      showQ();
    }
  }
  
  
  window.onload =init;
  
  
  function init()
  {
    correctCount = 0;
    questions.sort(randSort);
    currentQ = 0;
    showQ();
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
      background-position: center;
      background-color:lime;
  }
  
  #questionText {width: 350px; background: white;}
  
  
  #nextbutton {
      background-image: url(Buttons/nextbutton.jpg);
      background-size:contain;
      background-repeat:repeat-y;
      background-position: center;
      width:100px;
      height:44px;
      margin-left: 250px;
      border-radius:10px;
  }
  
  
  #main {
    margin-top:200px;
    margin-left:250px;
    border:1px solid red;
    width:600px;
  
  }
  
  #display {
      width:150px;
      height:50px;
      background-color:blue;
      color:white;
      border-radius:5px;
      font-family:aqua;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id = main&gt;
    &lt;div id = "questionText"&gt; Testing&lt;/div&gt;
    &lt;div id ="animal"&gt;
      &lt;img id = "animalPrint" src = "AnimalPrints/1.jpg"&gt;
    &lt;/div&gt;
  
    &lt;div id = "alloptions"&gt; &lt;/div&gt;
  
    &lt;button id = "nextbutton" onclick = "nextQ();"&gt;&lt;/button&gt;
  &lt;/div&gt;
  &lt;div id = "display"&gt;    Score:  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>