i can't figured out why my code won't work. I'm trying to create a little modulo calculator and i'm pretty new to javascript and came up with this code.
<!DOCTYPE html>
<html>
<head>
<title>Modulo Calculator</title>
</head>
<body>
Modulo Caculator
<script>
var x = myModulo(5,3); //enter numbers here
function myModulo(a,b) {
return a % b
};
</script>
</body>
</html>
It should return 2 but i know i'm missing something somewhere, but what?
All of your code is correct and should work just fine. You need to actually display the result of this using a piece of JavaScript on the page load (for example).
In short, at the moment you have the result of your JavaScript function
myModulo(5, 3)stored in the variable x. Now you haven't actually told the browser where to display this returned integer value - or even when to call the function in the DOM.You might want to try...
and having a
divorpelement (for example) which have theoutputid - i.e.<div id="output"></div>