JavaScript modulo condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaydel bujawe
    New Member
    • Mar 2012
    • 4

    JavaScript modulo condition

    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?
  • jaydel bujawe
    New Member
    • Mar 2012
    • 4

    #2
    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?

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      "modulo operator" is the appropriate keyword

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        what does your code look like (even if it does not yet work)?

        Comment

        • jaydel bujawe
          New Member
          • Mar 2012
          • 4

          #5
          java script

          Originally posted by Dormilich
          what does your code look like (even if it does not yet work)?
          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
          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:
          <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;
           }
          
          }
          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.
          Last edited by Dormilich; Mar 19 '12, 11:35 AM. Reason: Please use [CODE] [/CODE] tags when posting code.

          Comment

          • jaydel bujawe
            New Member
            • Mar 2012
            • 4

            #6
            Originally posted by Dormilich
            what does your code look like (even if it does not yet work)?
            please help me. I don't know what to do anymore. thanks!

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              [merging threads about same topic]

              Comment

              Working...