+ 1
Can u help me Guyz in this calc
9 Answers
+ 12
Just made a demo, there are anyway different ways to do the same thing and i tried to choose the more readable, try to experiment on your own the others... or why not? Make some controls.
What if i add a character "a" rather than a number?
Have fun! :)
https://code.sololearn.com/WMG9EWqqG713/?ref=app
+ 11
You called in a bad way the function at the onclick (you forgot to insert the parenthesis) and you make a calculation between two DOM elements and not their value.
Basically this is a way to solve pretty easy:
function plus(){
var num1=document.getElementById("num1").value;
var num2=document.getElementById("num2").value;
return parseInt(num1) + parseInt(num2);
}
function answer(){
alert (plus());
}
In the first lines you obtain id's value and in the return value you make an addition between their value converting it in an integer number.
+ 10
I edited, now it is more clear i hope! ^^
+ 3
@Coder parseInt is a JavaScript method for type conversion, specifically for converting strings to Integers...
it is used like this :
var myNum = parseInt("100");
// this outputs 100.
Another method for similar type conversion is parseFloat(); for converting strings to Floats...
0
Just tell me what is missing
0
What does parseint do
0
Thx
0
It doesnt work
0
Thx ure awesome maz