Im trying to convert characters to integers then add them. I have a JS input tag to take in the the text, then convert it to an integer using the parse int. Unfortunately, it gives back NaN when i enter in the value a, which is the only one . have declared right now. Here is my code
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<center>
<div class="">
Enter the first number: <input type="text" id="txt1" ><br >
Enter the seccond number: <input type="text" id="txt2" ><br >
Enter the third number: <input type="text" id="txt3" ><br >
Enter the fourth number: <input type="text" id="txt4" ><br >
Enter the fifth number: <input type="text" id="txt5" ><br >
Enter the sixth number: <input type="text" id="txt6" ><br >
</div>
</center>
<center><input type="button" onclick="call()" value="Add" >
</center>
<p id="output"> "Grade 1"</p>
<script>
var a = parseInt("4")
function call() {
var y = parseInt(document.getElementById("txt1").value);
var yy = parseInt(document.getElementById("txt2").value);
var yyy = parseInt(document.getElementById("txt3").value);
var yyyy = parseInt(document.getElementById("txt4").value);
var yyyyy = parseInt(document.getElementById("txt5").value);
var yyyyyy = parseInt(document.getElementById("txt6").value);
var result = (y + yy + yyy + yyyy + yyyyy + yyyyyy) / 6 ;
document.getElementById("output").innerHTML = result;
}
</script>
</body>
</html>
"; //10 var b = parseInt("10.00") + "
"; //10 var c = parseInt("10.33") + "
"; //10 var d = parseInt("34 45 66") + "
"; //35 var e = parseInt(" 60 ") + "
"; //60 var f = parseInt("40 years") + "
"; //40 var g = parseInt("He was 40") + "
"; NaN – Vicky charanpahari Feb 03 '18 at 19:20