From 5ba098406e99b84cfb8697e75bb1af7fe6863e60 Mon Sep 17 00:00:00 2001 From: IAlexanderM Date: Tue, 1 Aug 2023 01:35:23 +0500 Subject: [PATCH] update --- bjs/07_Number_and_string/index.html | 34 +++++++++-- bjs/07_Number_and_string/script.js | 91 ++++++++++++++++++++++++++++- bjs/07_Number_and_string/style.css | 6 ++ 3 files changed, 125 insertions(+), 6 deletions(-) diff --git a/bjs/07_Number_and_string/index.html b/bjs/07_Number_and_string/index.html index 645e1c0f..d4dbe7ff 100644 --- a/bjs/07_Number_and_string/index.html +++ b/bjs/07_Number_and_string/index.html @@ -18,14 +18,40 @@
- -
-
+ + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ - + diff --git a/bjs/07_Number_and_string/script.js b/bjs/07_Number_and_string/script.js index 4085abce..27170897 100644 --- a/bjs/07_Number_and_string/script.js +++ b/bjs/07_Number_and_string/script.js @@ -3,10 +3,97 @@ let operation = null; const inputWindow = document.getElementById('inputWindow'); - -document.getElementById('btn_clr').addEventListener('click', function () { +document.querySelector('#btn_clr').addEventListener('click', function () { lastOperand = 0; operation = null; inputWindow.value = ''; }) +document.querySelector('#btn_1').addEventListener('click', function () { + inputWindow.value += '1'; +}) +document.querySelector('#btn_2').addEventListener('click', function () { + inputWindow.value += '2'; +}) +document.querySelector('#btn_3').addEventListener('click', function () { + inputWindow.value += '3'; +}) +document.querySelector('#btn_4').addEventListener('click', function () { + inputWindow.value += '4'; +}) +document.querySelector('#btn_5').addEventListener('click', function () { + inputWindow.value += '5'; +}) +document.querySelector('#btn_6').addEventListener('click', function () { + inputWindow.value += '6'; +}) +document.querySelector('#btn_7').addEventListener('click', function () { + inputWindow.value += '7'; +}) +document.querySelector('#btn_8').addEventListener('click', function () { + inputWindow.value += '8'; +}) +document.querySelector('#btn_9').addEventListener('click', function () { + inputWindow.value += '9'; +}) +document.querySelector('#btn_0').addEventListener('click', function () { + inputWindow.value += '0'; +}) +document.querySelector('#btn_sum').addEventListener('click', function () { + lastOperand = parseInt(inputWindow.value); + operation = 'sum'; + inputWindow.value = ''; +}) +document.querySelector('#btn_dif').addEventListener('click', function () { + lastOperand = parseInt(inputWindow.value); + operation = 'dif'; + inputWindow.value = ''; +}) +document.querySelector('#btn_mult').addEventListener('click', function () { + lastOperand = parseInt(inputWindow.value); + operation = 'mult'; + inputWindow.value = ''; +}) +document.querySelector('#btn_div').addEventListener('click', function () { + lastOperand = parseInt(inputWindow.value); + operation = 'div'; + inputWindow.value = ''; +}) +document.querySelector('#btn_sqrt').addEventListener('click', function () { + lastOperand = parseInt(inputWindow.value); + operation = 'sqrt'; + inputWindow.value = ''; +}) + +document.querySelector('#btn_calc').addEventListener('click', function () { + if (operation === 'sum'){ + const result = lastOperand + parseInt(inputWindow.value); + operation = null; + lastOperand = 0; + inputWindow.value = result; + } + if (operation === 'dif'){ + const result = lastOperand - parseInt(inputWindow.value); + operation = null; + lastOperand = 0; + inputWindow.value = result; + } + if (operation === 'mult'){ + const result = lastOperand * parseInt(inputWindow.value); + operation = null; + lastOperand = 0; + inputWindow.value = result; + } + if (operation === 'div'){ + const result = lastOperand / parseInt(inputWindow.value); + operation = null; + lastOperand = 0; + inputWindow.value = result; + } + if (operation === 'sqrt'){ + const result = Math.sqrt(lastOperand); + operation = null; + lastOperand = 0; + inputWindow.value = result; + } +}) \ No newline at end of file diff --git a/bjs/07_Number_and_string/style.css b/bjs/07_Number_and_string/style.css index 5257d402..54434020 100644 --- a/bjs/07_Number_and_string/style.css +++ b/bjs/07_Number_and_string/style.css @@ -7,3 +7,9 @@ text-align: end; font-size: x-large; } +.btn { + border: 1px solid transparent; } +.card-body { + background-color: black; +} +