...

View Full Version : Array/Validation



Saakashvili
12-12-2009, 07:07 AM
--Got it.

Philip M
12-12-2009, 08:38 AM
Homework? :rolleyes:

Do it like this:-


<script type = "text/javascript">
function GetExamGrade () {
var ex;
var examReturn = 0;
examNumber = parseInt(prompt("Number of exams?",""));
examGrade = new Array(examNumber);
for (var i = 1; i <= examNumber; i++) {
ex= parseInt(prompt("Enter exam score " + (i) +"! ",""));
examGrade[i] = ex;
if ((isNaN(ex)) || (ex < 0) || (ex > 105)) {
alert("Your number must be at least 0 and not more than 105!");
i --;
}

examReturn += (examGrade[i] / i);
}

return examReturn;
}

</script>


Quizmaster: La Stampa and La Repubblica are newspapers published in which European country?
Contestant: Mexico

Saakashvili
12-12-2009, 10:13 AM
Homework? :rolleyes:

Do it like this:-


<script type = "text/javascript">
function GetExamGrade () {
var ex;
var examReturn = 0;
examNumber = parseInt(prompt("Number of exams?",""));
examGrade = new Array(examNumber);
for (var i = 1; i <= examNumber; i++) {
ex= parseInt(prompt("Enter exam score " + (i) +"! ",""));
examGrade[i] = ex;
if ((isNaN(ex)) || (ex < 0) || (ex > 105)) {
alert("Your number must be at least 0 and not more than 105!");
i --;
}

examReturn += (examGrade[i] / i);
}

return examReturn;
}

</script>


Quizmaster: La Stampa and La Repubblica are newspapers published in which European country?
Contestant: Mexico

It's more of a side-project I'm doing for an internship.

I'm required to use the the GetValidInput function for all input verification.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum