lundi 19 décembre 2016

How to change the popup window's score to a percentage?

I have a very simple question, which is quite urgent as well as I have to submit this coursework tomorrow :/ ..

So I am trying to create a basic IQ Test with Javascript, containing only 6 questions. If you get all questions right and after you click submit, the automatic pop up window will give you a score of 6. However I want it to show a percentage based on the number of correct answers.. Any kind of help would be much appreciated guys !!! Here's what I ve tried (you'll see that my problem probably is in the variables):

function calculate() {

var x, y, score;

y;

x = document.personalinfo.firstname.value;

score = (y*100)/6;

window.alert("Hey " + x + ", your score is: " + score);

if(document.IQTest.Q1[0,1,3,4].checked == true) score++;

if(document.IQTest.Q2[2].checked == true) score++;

if(document.IQTest.Q3[1].checked == true) score++;

if(document.IQTest.Q4[3].checked == true) score++;

if(document.IQTest.Q5[2].checked == true) score++;

if(document.IQTest.Q6[0,2,4].checked == true) score++;

}

Aucun commentaire:

Enregistrer un commentaire