lundi 23 février 2015

Basic Javscript For Loop giving inaccurate results...What's Wrong?

I am running a basic for loop to prompt a user for 12 test results. The for loop will then test to see if the "result" will be a 1 for passing or 2 for failing and then display the number of each. For some reason the program keeps giving me 12 passing students even though that is not what was entered. What seems to be the issue.



var i=0;
var passing=0;
var failing=0;

for (i=0; i<12; i++) {
var result = parseInt(prompt("Enter Results"));
if (result=1){
passing++;
} else if (result=2) {
failing++;
}

}
document.getElementById("passing").innerHTML = "Number of students who passed:" + passing;
document.getElementById("failing").innerHTML = "Number of students who failed:" + failing;
if (passing > 9) {
document.write("Tuition Raised");
} else {document.write("Tuition will remain the same.")}

Aucun commentaire:

Enregistrer un commentaire