How to Find the Modulus of Division With Javascript

The modulus operator in Javascript is a type of division operator. When you divide two numbers and there is a remainder, the modulus operator returns the remainder as an integer. This is beneficial when you do arithmetic operations on your web pages. Using modulus in Javascript is only a matter of dividing two numbers and placing the result into a variable.

Instructions

    • 1

      Right-click your HTML file and select "Open With." Select "Notepad," or another HTML editor, from the list of programs and click "OK."

    • 2

      Add the Javascript blocks in the "<head>" and "</head>" tags of your HTML code. These tags are used to contain all your Javascript code. Type the following code into your file:

      <script language="Javascript"> </script>

    • 3

      Type the arithmetic code. The following code divides 7 by 5, so the modulus result is 2:

      var result = 7 % 5;

      alert (result);

      The "alert" function is used to test the code and display a dialog box that shows the division results.

    • 4

      Click the "Save" button. Double-click the file to open your new changes in a web browser. The alert dialog box will pop up and show you the result of your modulus operation.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured