I am a beginner in javascript, i am trying made a input tag with the type number. and links the javascript file with my html file. this is my HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://mauriciopoppe.github.io/function-plot/js/function-plot.js"></script>
<title>Document</title>
<script src="exerciseJavascript.js"></script>
</head>
<body>
<input id="hello" type="number" value=2 oninput="putInConsole();">
</body>
</html>
this is my javascript
var x = document.querySelector("#hello").value;
function putInConsole(){
console.log(x);
}
and the error shown in the console is '''
0: Unable to get property 'value' of undefined or null reference
exerciseJavascript.js (1,1)
I dont know why the value is undefined. please help me with it