Skip to content

Instantly share code, notes, and snippets.

@trplll
Created August 23, 2017 05:51
Show Gist options
  • Save trplll/065ca815e9e28f5458ab1da8786f3016 to your computer and use it in GitHub Desktop.
Save trplll/065ca815e9e28f5458ab1da8786f3016 to your computer and use it in GitHub Desktop.
Modulus example in js
<!DOCTYPE html>
<html>
<body>
<h2>The % Operator</h2>
<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>
<script>
var x =57304;
var y = 12;
var z = x % y;
var a= x-(Math.floor(x/y)*y);
document.getElementById("demo").innerHTML = "x:"+x;
document.getElementById("demo1").innerHTML = "y:"+y;
document.getElementById("demo2").innerHTML = "x % y = "+z;
document.getElementById("demo3").innerHTML ="57304-( Math.floor ( 44775.333333333333) * 12) = " + a + x/y ;
document.getElementById("demo4").innerHTML ="x-( Math.floor ( x / y ) * y) = " +a;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment