how can you say it in a decision using if in java script that you only do the condition if two variables can be divided but should be without remainders?
JavaScript modulo condition
Collapse
X
-
-
java script
What code is needed if i make a "while" loop in java script and inside it there's an "if" which makes decision. And the condition is i have to divide two variables. the one variable is asked from the user and the other variable is set to 2.So, the condition to continue the if is if the two variables is divided without remainders and the else portion is to add 1 to the variable that we set to 2.how can i do that in java script? -
java script
this is how it looks like in pseudocode. i can't convert it to java script starting from the while loop. this is how my code looks like..Code:begin input N set F to 2 while N > 1 if N divides F without a remainder then output F set N to N / F else add 1 to F end if end while end
and this is how my code looks and its not working because i don't know how to program it to know that when they divide, it should not have a denominator.Code:<script> var userNum = prompt("Please supply an integer which is > (greater than) 1"); document.write("entered number is " + userNum); var factor = 2; while (userNum > 1) { if ((userNum/factor)== wholenumber){ document.write(userNum + "<br /> is "); } else { factor + 1; } }Last edited by Dormilich; Mar 19 '12, 11:35 AM. Reason: Please use [CODE] [/CODE] tags when posting code.Comment
-
Comment
Comment