Beep
07-26-2002, 05:14 PM
Is it possible to use the modulus operator in a condition?
With forum help, I've done the code for an addition (and subtraction and mult. ) game for my 8 year old. For division, I want the answer to be whole numbers. Tried using modulus operator as a condition but it doesn't seem to work in my several syntax efforts. Any suggestions? Ex:
function newProblem(){
numA = Math.floor(Math.random() * 100) + 1;
numB = Math.floor(Math.random() * 100) + 1;
if (numA%numB=0){
document.myForm.txtQuestion.value = + numA + " / " + numB;
var correctAnswer = numA/numB;
document.myForm.correctAnswer.value = correctAnswer;
document.myForm.txtAnswer.value = '';
} else {
newProblem();
}
}
Curious also: Is there a way to write a compound condition? So far I don't see this in any book or tutorial I have looked at. Previous attempts to solve the division problem involved trying to make a compound condition as in varieties of: if (numA>=numB) and if (numA%numB=0).
Thanks.
Beep
With forum help, I've done the code for an addition (and subtraction and mult. ) game for my 8 year old. For division, I want the answer to be whole numbers. Tried using modulus operator as a condition but it doesn't seem to work in my several syntax efforts. Any suggestions? Ex:
function newProblem(){
numA = Math.floor(Math.random() * 100) + 1;
numB = Math.floor(Math.random() * 100) + 1;
if (numA%numB=0){
document.myForm.txtQuestion.value = + numA + " / " + numB;
var correctAnswer = numA/numB;
document.myForm.correctAnswer.value = correctAnswer;
document.myForm.txtAnswer.value = '';
} else {
newProblem();
}
}
Curious also: Is there a way to write a compound condition? So far I don't see this in any book or tutorial I have looked at. Previous attempts to solve the division problem involved trying to make a compound condition as in varieties of: if (numA>=numB) and if (numA%numB=0).
Thanks.
Beep