Hi I'm new to javascript and I'm practicing it by making an HTML file that has two inputs Number1 and Number2 and when I click the button the program should show me by using alert() the sum of the two numbers but I'm having a problem that it tells me the function that I created is not a function
Code:
function add() {
var nm1, nm2, res;
nm1 = document.getElementById('nm1').value;
nm2 = document.getElementById('nm2').value;
res = nm1 + nm2;
return res;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href='style.css'>
<script src='train.js'></script>
<title>Document</title>
</head>
<body>
<h1>Hello world</h1>
<form action="#" name='add'>
<label>Number1:</label><input type='number' name='nm1' id='nm1'>
<label>Number2:</label><input type="number" name='nm2' id='nm2'>
<input type="button" onclick="alert(add())" value="Add">
</form>
</body>
</html>
the error is:
Uncaught TypeError: add is not a function