Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction error comparing radio button results to array value
    primarykey
    data
    text
    <p>I'm trying to check an answer from radio buttons. There are only two option, I'm trying to use selectedIndex and then check the answer with a value put in another array. The question and answer arrays are both working fine, but regardless of the answer that is checked, the function considers it the correct one and adds a score to my global score counter variable. The answers array contains only the numbers 1 or 2 in each slot depending on the question, so I'm not sure why it's not working.</p> <pre><code>function checkAnswer0() { if((document.getElementById('trueorfalse0').selectedIndex = 1) &amp;&amp; (answersPushed[0] == 1)) { scoreCounter++; document.getElementById("warning").innerHTML = "Correct Answer"; } else if((document.getElementById('trueorfalse0').selectedIndex = 2) &amp;&amp; (answersPushed[0] == 2)) { scoreCounter++; document.getElementById("warning").innerHTML = "Correct Answer"; } else{ document.getElementById("warning").innerHTML = "Wrong Answer"; } </code></pre> <p>}</p> <p>My form section looks like this and is held in the body within form tags.</p> <pre><code>&lt;input name="Answer0" type="radio" id="trueorfalse0" value="true" onclick="checkAnswer0()"/&gt; True &lt;br/&gt; &lt;input name="Answer0" type="radio" id="trueorfalse0" value="false" onclick="checkAnswer0()" /&gt; False </code></pre> <p>If anyone can help me understand the nature of the problem I'd appreciate it. I know there are many alternative ways to have approached the problem but I'd like to sort out in my head why this one isn't happening for me. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload