I think i have some problems with var totalScore. The code don't process on to certification.html page. Can someone help ?Code:<html> <body> <form name="myForm"> Question 1: Which of these is a letter?<br> <input type="radio" name="q1" value="correct">A<br> <input type="radio" name="q1">1<br> <input type="radio" name="q1">#<br> <input type="radio" name="q1">None of the Above<br> <br> <br> Question 2: Which of these is a number?<br> <input type="radio" name="q2">A<br> <input type="radio" name="q2" value="correct">1<br> <input type="radio" name="q2">#<br> <input type="radio" name="q2">None of the Above<br> <br> <br> Question 3: Which of these is a symbol?<br> <input type="radio" name="q3">A<br> <input type="radio" name="q3">1<br> <input type="radio" name="q3" value="correct">#<br> <input type="radio" name="q3">None of the Above<br> <br> <br> Question 4: Which of these is a comma?<br> <input type="radio" name="q4">A<br> <input type="radio" name="q4">1<br> <input type="radio" name="q4">#<br> <input type="radio" name="q4" value="correct">None of the Above<br> <br> <br> <a href="#" onclick="return checkAnswers()">Get Certificate</a> </form> </body> </html> <script language="JavaScript"> var allQuestions = new Array(document.myForm.q1, document.myForm.q2, document.myForm.q3, document.myForm.q4); function checkAnswers(){ var totalScore = 0; for (var i = 0; i < allQuestions.length; i++) { if (allQuestions[i].value == "correct" && allQuestions[i].checked == true) { totalScore++; } } if ((totalScore/allQuestions.length) >= .75) { alert("Congratulations! Your score of " + totalScore + " out of " + allQuestions.length + " is good enough to proceed!"); window.location.href = "certificate.html"; } else{ alert("You must get at least 75% correct to move on!"); return false; } } </script>


Reply With Quote
Bookmarks