|
Post by wingly on Aug 7, 2017 13:52:51 GMT -5
I need help trying to figure out what is wrong with my code. I figured that there must be someone here who knows javascript that could help me. I am trying to divide two numbers and show two results. One with / and one showing the remainder %. I can't figure out what I am doing wrong.
<html>
<head>
</head>
<body>
Lets reduce a fraction
<br>
<!-- get user input You want number input not text-->
<input id="numerator" type="number" />Numerator <br>
<input id="denominator" type="number" />Denominator<br>
<!-- with onclick=" you forgot the closing " its to be onlick="divdeby()"-->
<button id="clickMe" type="button" value="divideby" onclick="divideby()">Press For Result</button>
<!-- </form> -->
<p> The Result is : <br>
<span id = "result"></span>
<script type="text/javascript">
function divideby(){
var num1 = document.getElementById("numerator").value;
var num2 = document.getElementById("denominator").value;
document.getElementById("result").innerHTML = num1 / num2;
}
function remainder(){
var num1 = document.getElementById("numerator").value;
var num2 = document.getElementById("denominator").value;
document.getElementById("result").innerHTML = num1 % num2;
}
</script>
</body>
</html>
|
|
|
Post by psychoghost on Aug 7, 2017 22:00:38 GMT -5
Hello Wingly
Your problem is that the function remainder is not called ! If you want to display both results with 1 button would be a possible solution :
<html>
<head>
</head>
<body>
Lets reduce a fraction
<br>
<!-- get user input You want number input not text-->
<input id="numerator" type="number" />Numerator <br>
<input id="denominator" type="number" />Denominator<br>
<!-- with onclick=" you forgot the closing " its to be onlick="divdeby()"-->
<button id="clickMe" type="button" value="divideby" onclick="divideby()">Press For Result</button>
<!-- </form> -->
<p> The Result is : <br>
<span id = "result"></span> <br> <span id = "result2"></span>
<script type="text/javascript">
function divideby(){
var num1 = document.getElementById("numerator").value;
var num2 = document.getElementById("denominator").value;
document.getElementById("result").innerHTML = num1 / num2;
<!-- remainder -->
var num1 = document.getElementById("numerator").value;
var num2 = document.getElementById("denominator").value;
document.getElementById("result2").innerHTML = num1 % num2;
}
</script>
</body>
</html>
|
|
|
Post by wingly on Aug 8, 2017 0:00:16 GMT -5
thank you so much! this was driving me crazy!
|
|