From 2dfb3c2d51fd80777b30c0ce0b80f2fee8e74223 Mon Sep 17 00:00:00 2001 From: Aryan <157914657+AddisionS@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:09:27 +0530 Subject: [PATCH] Added files --- favicon.png | Bin 0 -> 501 bytes index.html | 38 +++++++++++++++ script.js | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 82 ++++++++++++++++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 favicon.png create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..11307d64b6b0fe9d3f158f0b5388eb9addadfc35 GIT binary patch literal 501 zcmV{uh(Rfl1Z2-$AZQ<6kq#h(Pz-K|5 zo?cwTdT9exZ7mXur3#!~-iQo*$YdaJQ~YpL@v3j4Toq;^b^|{J=!ZvO7)B^|^zN@c zQZ*1(yib)31b{MNO%j6x{yY*5G2}#{ITILb2STjE0~*E$jhUF#@EafBtDa~P%-NlTTF1Zh}VH} zm?)O3aDH_gY{2I4G6n{ss3b*ZyZ50D;NwEt!Y!XKlWj!?__&a^c;>i0De>Q#7*FbW rKQB5H@rvd%EF0;_69@!?k`z7x{Q*S9AaWrT00000NkvXXu0mjfmq*es literal 0 HcmV?d00001 diff --git a/index.html b/index.html new file mode 100644 index 0000000..c33fd65 --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + + + + + + Calculator App + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..178f454 --- /dev/null +++ b/script.js @@ -0,0 +1,132 @@ +const screen = document.querySelector(".screen"); + +let troll = 0; +let result = 0; +let countLP = 0; +let countRP = 0; +let lastChar = screen.value.slice(-1); + +function backspace() { + + if (troll || result) { + screen.value = ""; + troll = 0; + result = 0; + } + + let removedChar = screen.value.slice(-1); + + screen.value = screen.value.slice(0, -1); + + if (removedChar === ')') { + countRP -= 1; + } else if (removedChar === '(') { + countLP -= 1; + } + + lastChar = screen.value.slice(-1); +} + +function getLastNumber(expression) { + const numbers = expression.split(/[\+\-\*\/]/); + return numbers[numbers.length - 1]; +} + +const operators = ['+','-','*','/']; +const numbers = ['0','1','2','3','4','5','6','7','8','9','.']; +const forbiddenFromFirst = ['/','*',')']; + +function isLastCharNum() { + if (numbers.includes(lastChar)) { + return 1; + } else { + return 0; + } +} + +function isLastCharOperator() { + if (operators.includes(lastChar)) { + return 1; + } else { + return 0; + } +} + +function showDisplay(input) { + + lastChar = screen.value.slice(-1); + + if (troll || result) { + screen.value = ""; + troll = 0; + result = 0; + } + + if (input === '.') { + const lastNumber = getLastNumber(screen.value); + if (lastNumber.includes('.')) { + return; + } + } + + if (screen.value.length === 0 && forbiddenFromFirst.includes(input)) { + return; + } + + if (operators.includes(input) && isLastCharOperator()) { + return; + } + + if (input === '(') { + if (isLastCharNum()) { + return; + } + countLP += 1 + } + + if (input === ')') { + if (countLP === 0) { + return; + } + countRP += 1 + } + + if (numbers.includes(input) && lastChar === ')') { + return; + } + + screen.value += input; +} + +function wipe() { + screen.value = ""; + troll = 0; + result = 0; + countLP = 0; + countRP = 0; +} + +function calculate() { + try{ + if (screen.value.trim() === "") { + screen.value = "Enter an expression"; + return; + } + if (countLP === countRP) { + screen.value = eval(screen.value); + result = 1; + countLP = 0; + countRP = 0; + } else { + screen.value = "Close all parenthesis" + troll = 1; + countLP = 0; + countRP = 0; + } + }catch(e) { + screen.value = "Quit Trolling"; + troll = 1; + countLP = 0; + countRP = 0; + } +} \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..c1b18ff --- /dev/null +++ b/style.css @@ -0,0 +1,82 @@ +@import url('https://fonts.googleapis.com/css2?family=Playwrite+DE+Grund:wght@100..400&display=swap'); + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +html{ + display: flex; + align-items: center; + justify-content: center; + font-family: "Playwrite DE Grund", cursive; +} + +.body { + max-width: 500px; + overflow: hidden; + margin-top: 80px; + border-radius: 20px; + background-color: rgba(0, 0, 0, 0.782); + padding: 15px; +} + +.screen { + width: 100%; + padding: 20px; + border: none; + border-radius: 20px; + text-align: right; + font-family: "Playwrite DE Grund", cursive; + font-weight: bold; + font-size: 1.5rem; + background-color: rgba(0, 0, 0, 0.236); + color: white; + outline: none; + +} + +.btn { + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + width: 75px; + height: 75px; + border-radius: 50px; + border: none; + font-family: "Playwrite DE Grund", cursive; + font-weight: bold; + font-size: 1rem; + transition: transform 0.2s ease-in-out; +} + +.btn:hover{ + transform: scale(1.1); +} + +.buttonHolder { + padding: 10px; + display: grid; + grid-template-columns: repeat(4, 1fr); + gap: 10px; +} + +.normal-btn { + background-color: rgb(181, 181, 181); +} + +.normal-btn:active { + background-color: rgba(181, 181, 181, 0.637); + +} + +.operations { + background-color: rgb(0, 213, 255); +} + +.operations:active { + background-color: rgb(0, 213, 255, 0.637); +} +