Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am getting this answer if x=5
and y=6 then x+y=56

What I have tried:

<script type="text/javascript">
function hi(){
	alert("ji");
	var x=document.getElementById("f").value;
	var y=document.getElementById("ff").value;
	alert("x ="+x+"y ="+y);
	var z=x+y;// here i get the output as 45, if x=4 and y=5
	alert("z = "+z);
	document.getElementById("fff").innerHTML=z;

}
Posted
Updated 26-Feb-18 18:33pm

1 solution

The code need to parse the x and y int before adding them. Here how to use the parseint function

JavaScript parseInt() Function[^]
 
Share this answer
 
Comments
Karthik_Mahalingam 27-Feb-18 2:59am    
5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900