1. Engineering
  2. Computer Science
  3. hello i am trying to write a function in javascript...

Question: hello i am trying to write a function in javascript...

Question details

Hello. I am trying to write a function in JavaScript where the user inputs their career yards and below they input their season yards. The function is then supposed to add the two numbers together but instead it is just combining them as if they where two strings. I have supplied the code below, your help will be greatly appreciated.

<form>
<fieldset>
<label for="careerValue">
<h4>Career yardage prior to 2018:</h4>
</label>
<h4><input type="number" id="careerValue" /></h4>
<label for="seasonValue">
<h4>Career yardage prior to 2018:</h4>
</label>
<h4><input type="number" id="seasonValue" /></h4>
</fieldset>
<fieldset>
<h4><button type="button" id="button">Update Career Yardage</button><h4>
</fieldset>
<fieldset>
Updated Career Yardage:
<p id="totalValue">&nbsp;</p>
</fieldset>
</form>
<script>
function passYds() {
var careerNum = document.getElementById("careerValue").value;
var seasonNum = document.getElementById("seasonValue").value;
var updateTotal = (careerNum + seasonNum);
document.getElementById("totalValue").innerHTML = updateTotal;
}
document.getElementById("button").
addEventListener("click", passYds, false);
</script>

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution