I am attempting to create a calculator like thing. I have a custom function that is suppose to load input value from two variables and them put them together but it did not work, so I checked with console log if it loads the input value, and all it says is that the values are undefined. Any idea how to fix this please?
let num1 = document.getElementById("number1").value,
num2 = document.getElementById("number2").value,
operator = document.getElementById("select"),
resolutor = document.getElementById("resolute"),
res = document.getElementById("result");
function mathoperation(num1, num2) {
let value = operator.value,
result;
switch (value) {
case "plus":
console.log(num1); //console says unindefied
console.log(num2); //console says unindefied
break;
}
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Úloha 18.1</title>
</head>
<body>
<input type="text" id="number1">
<select name="" id="select">
<option value="plus">+</option>
<option value="minus">-</option>
<option value="krat">*</option>
<option value="deleno">/</option>
</select>
<input type="text" id="number2">
<input type="button" id="resolute" value="=" onclick="mathoperation()">
<input type="text" id="result" readonly>
</body>
</html>