Md.Riyaz
-
Posts
2 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by Md.Riyaz
-
-
Hello Gurus,
I'm a beginner to the Java Script.
While learning Arithmetic chapter, I just tried the below simple program. Everything is giving correct result except the addition operation.
I tried my best to understand and produce the result.
Could anyone point out/throw some light on what I'm doing wrong please.
<!DOCTYPE html>
<html>
<body>
<h1>Assigning Values</h1>
<p>In JavaScript the = operator is used to assign values to variables.</p>
<input type="number" id="a" value=5></input>
<input type="number" id="b" value=1></input>
<p id="+"></p>
<p id="-"></p>
<p id="YY"></p>
<p id="*"></p>
<p id="/"></p>
<script>
var x = document.getElementById( "a" ).value;
var y = document.getElementById( 'b' ).value;//document.getElementById("+").innerHTML = "Additon - " + (x + y) + typeof x;
//document.getElementById("+").innerHTML = (x + y) + " - Additon" ;
//document.getElementById("+").innerHTML = x + y;
document.getElementById("+").innerHTML = Number(x) + y;document.getElementById("-").innerHTML = x - y ;
document.getElementById("YY").innerHTML = "Subtraction - " + x - y ;
document.getElementById("*").innerHTML = "Multiplication - " + x * y;
document.getElementById("/").innerHTML = "Divide - " + x / y;
</script>
</body>
</html>Thanks in Advance.
Regards,
Md.Riyaz
JavaScript Addition Operation Problem
in JavaScript
Posted · Edited by Md.Riyaz
Thank you for your inputs Scientist,Dave and Ingolme.
I was thinking I have declared input type as number so obviously the variable also should be variable. With Ingolme statement i came to know everything coming from the form will always be the string.
Thanks,
Md