Пробую написать свой 2 калькулятор. В первом вместо кнопок использовались просто поля ввода (input). Сейчас решил усложнить себе задачу и не понимаю в чем дело. Кнопка почему-то вызывает сразу все функции, и также алертит только значение id '1' , то есть 1
p.s не гнобите плес за наименования переменных и тд, пока что учусь)
HTML
<div class="AllCalculator">
<div class="button-operations" id="operationsID">
<button id="Pluse">+</button>
<button id="Minus ">-</button>
<button id="Multiply">*</button>
<button id="Divide">/</button>
</div>
<div>
<hr>
</div>
<div class="button-number" id="numberID">
<button id="1" value="1">1</button>
<button id="2" value="2">2</button>
<button id="3" value="3">3</button>
<button id="4" value="4">4</button>
<button id="5" value="5">5</button>
<button id="6" value="6">6</button>
<button id="7" value="7">7</button>
<button id="8" value="8">8</button>
<button id="9" value="9">9</button>
<button id="0" value="0">0</button>
</div>
<div>
<hr>
</div>
<div class="button-equally"><button>=</button></div>
<div class="answer">Ответ:</div>
</div>
<link rel="stylesheet" href="CSS.css">
<script defer src="JS.js"></script>
JS
var numberless1 = document.getElementById('1')
var numberless2 = document.getElementById('2')
var numberless3 = document.getElementById('3')
var numberless4 = document.getElementById('4')
var numberless5 = document.getElementById('5')
var numberless6 = document.getElementById('6')
var numberless7 = document.getElementById('7')
var numberless8 = document.getElementById('8')
var numberless9 = document.getElementById('9')
var numberless0 = document.getElementById('0')
function number1() {
var elnumber111 = document.getElementById('1')
var elnumber1 = Number(elnumber111.value)
window.alert(elnumber1);
}
function number2() {
var elnumber222 = document.getElementById('2')
var elnumber2 = Number(elnumber222.value)
console.log(elnumber2)
}
function number3() {
var elnumber333 = document.getElementById('3')
var elnumber3 = Number(elnumber333.value)
console.log(elnumber3);
}
function number4() {
var elnumber444 = document.getElementById('4')
var elnumber4 = Number(elnumber444.value)
console.log(elnumber4)
}
function number5() {
var elnumber555 = document.getElementById('5')
var elnumber5 = Number(elnumber555.value)
console.log(elnumber5);
}
function number6() {
var elnumber666 = document.getElementById('6')
var elnumber6 = Number(elnumber666.value)
console.log(elnumber6)
}
function number7() {
var elnumber777 = document.getElementById('7')
var elnumber7 = Number(elnumber777.value)
console.log(elnumber7);
}
function number8() {
var elnumber888 = document.getElementById('8')
var elnumber8 = Number(elnumber888.value)
console.log(elnumber8)
}
function number9() {
var elnumber999 = document.getElementById('9')
var elnumber9 = Number(elnumber999.value)
console.log(elnumber9);
}
function number0() {
var elnumber000 = document.getElementById('0')
var elnumber0 = Number(elnumber000.value)
console.log(elnumber0)
}
numberless1 = addEventListener('click', number1)
numberless2 = addEventListener('click', number2)
numberless3 = addEventListener('click', number3)
numberless4 = addEventListener('click', number4)
numberless5 = addEventListener('click', number5)
numberless6 = addEventListener('click', number6)
numberless7 = addEventListener('click', number7)
numberless8 = addEventListener('click', number8)
numberless9 = addEventListener('click', number9)
numberless0 = addEventListener('click', number0)