I'm making AP calculator but the answer value is undefined in the input field of answer having id "An" please help; here's my code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Example</title>
</head>
<body>
<!-- first term -->
<input type="text" value="1" name="" id="a1" onkeyup="ap()">
<!-- number of term -->
<input type="text" value="2" name="" id="n" onkeyup="ap()">
<!-- difference -->
<input type="text" name="" value="3" id="d" onkeyup="ap()">
<input type="text" name="" id="An">
<script>
ap()
function ap() {
let a1 = document.getElementById("a1").value;
let n = document.getElementById("n").value;
let d = document.getElementById("d").value;
var An = Number(a1) + ((Number(n) - 1) * Number(d));
console.log(An)
document.getElementById("An").value = An.value
}
</script>
</body>
</html>