I am adding two number using JS function, when I put the values 1st time for example 3 + 4 my output come as "Your answer is 7" till here it's fine. However without refreshing when I put the different values 10 + 10 then my output become "Your answer is 7 10" it does not replace 7 instead it get added to that paragraph. what I need to change in code so I can get one value answer every time.
Many thanks in advance, Dhanajay
<p> Add two number </p>
<label for="value1">Enter Number 1</label>
<input type="text" id="value1" />
<br />
<br />
<label for="value2">Enter Number 2</label>
<input type="text" id="value2" />
<br />
<br />
<button id="calculate" type="button" onclick="myFunction()">Calculate</button>
<p id="answer">Your answer is </p>
<script type="text/javascript">
function myFunction() {
var y = document.getElementById("value1").value;
var z = document.getElementById("value2").value;
var x = +y + +z;
document.getElementById("answer").innerHTML = document.getElementById("answer").innerHTML + " " + x;
}
</script>
myFunction()does?