for a simple calculator i have used a form butI cannot get it done I just need help with JS to find out the following: first I need to have the values of variables num1, num2 and operator and second I need to make a function that does the calculation once the user clicks the equal button. please help
<form name="myform">
<input type="text" name="display" id="input" value=""><br>
<input class="digit" type="button" value="7" id="7" value="7">
<input class="digit" type="button" id="8" value="8">
<input class="digit" type="button" id="9" value="9"><br>
<input class="digit" type="button" id="4" value="4">
<input class="digit" type="button" id="5" value="5">
<input class="digit" type="button" id="6" value="6">
<input class="digit" type="button" id="1" value="1"><br>
<input class="digit" type="button" id="2" value="2">
<input class="digit" type="button" id="3" value="3">
<input class="digit" type="button" id="0" value="0">
<input class="digit" type="button" id="." value="."><br>
<input class="operator" id="opr" type="button" value="+">
<input class="operator" id="opr" type="button" value="-">
<input class="operator" id="opr" type="button" value="*">
<input class="operator" id="opr" type="button" value="/">
<input class="operator" type="button" value="=">
</form>
<script>
let numbers =
document.getElementsByClassName('digit')
let outPut =
document.getElementById('input')
let operator =
document.getElementsByClassName('operator'
)
//this section of the code targets the numbers in
for (i = 0; i < numbers.length; i++)
numbers[i].addEventListener('click', a => {
var btn = a.target;
outPut.value += btn.value;
console.log(outPut.value);
})
//this section targets the operator keys
for (i = 0; i < operator.length; i++)
operator[i].addEventListener('click', a => {
var btn = a.target; if (operator.value != "") {
outPut.value = "";
num1 = parseInt(outPut.value);
})
</script>