├── .gitignore ├── LICENSE ├── README.md ├── css ├── styles.css ├── theme1.css └── theme2.css ├── design ├── active-states-theme-1.jpg ├── active-states-theme-2.jpg ├── active-states-theme-3.jpg ├── desktop-design-theme-1.jpg ├── desktop-design-theme-2.jpg ├── desktop-design-theme-3.jpg ├── desktop-preview.jpg ├── mobile-design-theme-1.jpg ├── mobile-design-theme-2.jpg └── mobile-design-theme-3.jpg ├── images └── favicon-32x32.png ├── index.html ├── script.js └── style-guide.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Avoid accidental upload of the Sketch and Figma design files 2 | ##################################################### 3 | ## Please do not remove lines 5 and 6 - thanks! 🙂 ## 4 | ##################################################### 5 | *.sketch 6 | *.fig 7 | 8 | # Avoid accidental XD upload if you convert the design file 9 | ############################################### 10 | ## Please do not remove line 12 - thanks! 🙂 ## 11 | ############################################### 12 | *.xd 13 | 14 | # Avoid your project being littered with annoying .DS_Store files! 15 | .DS_Store 16 | .prettierignore -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Sarthak Sachdev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Calculator App 2 | 3 | ## Welcome! 👋 4 | 5 | ## Table of contents 6 | 7 | - [Overview](#overview) 8 | - [The challenge](#the-challenge) 9 | - [How to setup the project](#how-to-setup-the-project) 10 | - [Screenshot](#screenshot) 11 | - [Links](#links) 12 | - [My process](#my-process) 13 | - [Built with](#built-with) 14 | - [What I learned](#what-i-learned) 15 | - [Continued development](#continued-development) 16 | - [Useful resources](#useful-resources) 17 | - [Author](#author) 18 | - [Acknowledgments](#acknowledgments) 19 | 20 | ## Overview 21 | 22 | ### The challenge 23 | 24 | The challenge is to build a basic calculator app that allows users to perform arithmetic operations such as addition, subtraction, multiplication, and division. 25 | 26 | ### How to setup the project 27 | 28 | To set up the project locally, follow these steps: 29 | 30 | 1. Clone the repository using GitHub Desktop or Git Bash: 31 | ```bash 32 | git clone https://github.com/SartHak-0-Sach/Calculator-app_frontend_project.git 33 | ``` 34 | 2. Open the project folder in your code editor. 35 | 3. Run the project using a live server extension or deploy it using Netlify, Vercel, or another web hosting and deployment service. 36 | 37 | ### Screenshot 38 | 39 | ![Design Preview](./design/active-states-theme-1.jpg) 40 | 41 | ### Links 42 | 43 | - Solution URL: [GitHub Repository](https://github.com/SartHak-0-Sach/Calculator-app_frontend_project) 44 | - Live Site URL: [Live Site](https://calculator-frontend-app.netlify.app/) 45 | 46 | ## My process 47 | 48 | ### Built with 49 | 50 | - HTML5 51 | - CSS3 52 | - JavaScript 53 | 54 | You will find all the required assets in the `/images` folder. The assets are already optimized. 55 | 56 | There is also a `style-guide.md` file containing the information you'll need, such as color palette and fonts. 57 | 58 | ### What I learned 59 | 60 | This project even though seems very simple has been a rollercoaster in itself and has taught me a lot of using javaScript to handle buttons and operate on them as shown- 61 | ``` 62 | function handleClick(event) { 63 | const buttonValue = event.target.innerText; 64 | 65 | // Check the type of button clicked and perform the corresponding action 66 | if (buttonValue === "DEL") { 67 | // Handle delete button 68 | currentExpression = currentExpression.slice(0, -1); 69 | } else if (buttonValue === "RESET") { 70 | // Handle reset button 71 | currentExpression = ""; 72 | } else if (buttonValue === "=") { 73 | // Handle equal button 74 | try { 75 | const result = eval(currentExpression); 76 | output.innerText = formatNumberWithCommas(result); 77 | currentExpression = result.toString(); // Store the result as the new current expression 78 | } catch (error) { 79 | output.innerText = "Error"; 80 | currentExpression = ""; // Clear the current expression in case of an error 81 | } 82 | } else { 83 | // Handle normal buttons 84 | currentExpression += buttonValue; 85 | } 86 | 87 | // Update the screen output with formatted number 88 | output.innerText = formatNumberWithCommas(currentExpression); 89 | } 90 | ``` 91 | 92 | ### Continued development 93 | 94 | The continuously learning journey of a programmer never ends. This project made me realize that there are many concepts that I need to work upon including fundamentals like flex-box and its properties, to more complex concepts like working with fetch and async await in javascript. These areas are some that I think I need to work more upon in the upcoming future as they highlight some of the most significant regions of web development that are important for every developer to know of. 95 | 96 | These key points mentioned here will help me grow accountable and consistent towards improving at writing good quality code and be a successful full stack developer one day. 97 | 98 | ### Useful resources 99 | 100 | - [Harkirat Singh course notes](https://github.com/SartHak-0-Sach/harkirat-singh-course_code_and_notes) - I have added notes of all lectures along with code and lecture insights of all weeks along with bonus lectures to help you all as much as I can. 101 | - [My development code and notes](https://github.com/SartHak-0-Sach/cwh-web-dev-playlist_code_and_notes) - These are my notes that I made while working on my development skills in initial days and did these courses. Make sure to star the repository if you like it.✨💫 102 | - [mdn documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) - This is an amazing article which helped me finally understand promises, async and await syntax. I'd recommend it to anyone still learning this concept. 103 | 104 | ## Author 105 | 106 | Sarthak Sachdev 107 | - Website - [Sarthak Sachdev](https://itsmesarthak.netlify.app/) 108 | - LeetCode - [@sarthak_sachdev](https://leetcode.com/u/sarthak_sachdev/) 109 | - Twitter - [@sarthak_sach69](https://www.twitter.com/sarthak_sach69) 110 | 111 | ## Acknowledgments 112 | 113 | I feel like the solutions provided on the website and the continuous doubt solving by industry experts on discord for free is something that is unmatched by anyone else and need to be acknowledged for their efforts in improving me as a developer by suggesting the best practices in your respective tech stack. 114 | 115 | ## Got feedback for me? 116 | 117 | I love receiving feedback! I am always looking to improve my code and take up new innovative ideas to work upon. So if you have anything you'd like to mention, please email 'hi' at saarsaach30[at]gmail[dot]com. 118 | 119 | If you found this project helpful, consider sharing it with others to spread the knowledge! 120 | 121 | **Happy coding!** ☺️🚀 -------------------------------------------------------------------------------- /css/styles.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Spartan:wght@700&display=swap'); 2 | 3 | *, 4 | *::after, 5 | *::before { 6 | box-sizing: border-box; 7 | margin: 0; 8 | padding: 0; 9 | font-family: 'Spartan', sans-serif; 10 | font-size: 32px; 11 | } 12 | 13 | :root { 14 | --bg-theme: hsl(222, 26%, 31%); 15 | --bg-toggle-keypad: hsl(223, 31%, 20%); 16 | --bg-screen: hsl(224, 36%, 15%); 17 | --bg-del-reset-key: hsl(225, 21%, 49%); 18 | --key-shadow-del-reset: hsl(224, 28%, 35%); 19 | --bg-keys: hsl(30, 25%, 89%); 20 | --key-shadow-keys: hsl(28, 16%, 65%); 21 | --bg-result-toggle-key: hsl(6, 63%, 50%); 22 | --key-shadow-result: hsl(6, 70%, 34%); 23 | --text-color: hsl(221, 14%, 31%); 24 | } 25 | 26 | body { 27 | height: 100vh; 28 | background-color: var(--bg-theme); 29 | display: flex; 30 | justify-content: center; 31 | align-items: center; 32 | flex-direction: column; 33 | } 34 | 35 | label, 36 | h6 { 37 | font-size: 13px; 38 | color: var(--bg-keys); 39 | position: relative; 40 | left: 70px; 41 | } 42 | 43 | .calculator { 44 | display: flex; 45 | flex-direction: column; 46 | width: 300px; 47 | margin: auto; 48 | align-items: center; 49 | } 50 | 51 | .header { 52 | display: flex; 53 | margin: 50px 0 10px; 54 | position: relative; 55 | } 56 | 57 | .header>h1 { 58 | color: var(--bg-keys); 59 | position: absolute; 60 | left: -90px; 61 | top: -15px; 62 | } 63 | 64 | .header>h6 { 65 | align-self: center; 66 | } 67 | 68 | .input { 69 | height: 30px; 70 | width: 80px; 71 | border-radius: 30px; 72 | background-color: var(--bg-toggle-keypad); 73 | position: relative; 74 | left: 90px; 75 | } 76 | 77 | [id="theme1"], 78 | [id="theme2"], 79 | [id="theme3"] { 80 | appearance: none; 81 | position: absolute; 82 | width: 15px; 83 | height: 15px; 84 | border-radius: 30px; 85 | top: 7px; 86 | transition: 0.5s; 87 | } 88 | 89 | [id="theme1"] { 90 | left: 10px; 91 | } 92 | 93 | [id="theme2"] { 94 | left: 33px; 95 | } 96 | 97 | [id="theme3"] { 98 | left: 55px; 99 | } 100 | 101 | input:checked { 102 | background-color: var(--bg-result-toggle-key); 103 | } 104 | 105 | label { 106 | top: -40px; 107 | } 108 | 109 | label[for="theme1"] { 110 | left: 13px; 111 | } 112 | 113 | label[for="theme2"] { 114 | left: 20px; 115 | } 116 | 117 | label[for="theme3"] { 118 | left: 26px; 119 | } 120 | 121 | .user-input { 122 | background-color: var(--bg-screen); 123 | height: 80px; 124 | width: 100%; 125 | border-radius: 10px; 126 | margin-bottom: 15px; 127 | text-align: right; 128 | display: flex; 129 | flex-direction: column; 130 | justify-content: space-around; 131 | padding-right: 10px; 132 | color: white; 133 | overflow: hidden; 134 | } 135 | 136 | .user-input>.previous-operand { 137 | font-size: 15px; 138 | } 139 | 140 | .grid-container { 141 | display: grid; 142 | justify-content: center; 143 | align-items: center; 144 | grid-template-columns: repeat(4, 70px); 145 | grid-template-rows: repeat(5, 70px); 146 | background-color: var(--bg-toggle-keypad); 147 | padding: 15px 10px; 148 | border-radius: 10px; 149 | } 150 | 151 | .grid-container>button { 152 | margin: 0 8px; 153 | padding: 8px 0; 154 | border-radius: 5px; 155 | border: none; 156 | background-color: var(--bg-keys); 157 | color: var(--text-color); 158 | box-shadow: 0 5px var(--key-shadow-keys); 159 | } 160 | 161 | button:active { 162 | transform: translateY(2px); 163 | } 164 | 165 | .column-span { 166 | grid-column: span 2; 167 | } 168 | 169 | button:nth-child(17), 170 | button:nth-child(4) { 171 | background-color: var(--bg-del-reset-key); 172 | box-shadow: 0 5px var(--key-shadow-del-reset); 173 | color: var(--bg-keys); 174 | font-size: 18px; 175 | padding: 17px 0; 176 | } 177 | 178 | button:nth-child(18) { 179 | background-color: var(--bg-result-toggle-key); 180 | box-shadow: 0 5px var(--key-shadow-result); 181 | color: white; 182 | } 183 | 184 | /* Footer */ 185 | .attribution { 186 | left: 50%; 187 | font-size: 11px; 188 | text-align: center; 189 | } 190 | 191 | .attribution a { 192 | color: hsl(228, 45%, 44%); 193 | } 194 | 195 | @media only screen and (min-width: 1200px) { 196 | .calculator { 197 | width: 350px; 198 | } 199 | 200 | .grid-container { 201 | grid-template-columns: repeat(4, 82px); 202 | grid-template-rows: repeat(5, 65px); 203 | } 204 | 205 | .grid-container>button { 206 | margin: 0 8px; 207 | padding: 5px 0; 208 | } 209 | 210 | button:nth-child(17), 211 | button:nth-child(4) { 212 | padding: 13px 0; 213 | } 214 | } -------------------------------------------------------------------------------- /css/theme1.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --bg-theme: hsl(0, 0%, 90%); 3 | --bg-toggle-keypad: hsl(0, 5%, 81%); 4 | --bg-screen: hsl(0, 0%, 93%); 5 | --bg-del-reset-key: hsl(185, 42%, 37%); 6 | --key-shadow-del-reset: hsl(185, 58%, 25%); 7 | --bg-keys: hsl(45, 7%, 89%); 8 | --key-shadow-keys: hsl(35, 11%, 61%); 9 | --bg-result-toggle-key: hsl(25, 98%, 40%); 10 | --key-shadow-result: hsl(25, 99%, 27%); 11 | --text-color: hsl(60, 10%, 19%); 12 | } 13 | 14 | body { 15 | background-color: var(--bg-theme); 16 | } 17 | 18 | label, 19 | h6 { 20 | color: var(--text-color); 21 | } 22 | 23 | .header>h1 { 24 | color: var(--text-color); 25 | } 26 | 27 | .input { 28 | background-color: var(--bg-toggle-keypad); 29 | } 30 | 31 | input:checked { 32 | background-color: var(--bg-result-toggle-key); 33 | } 34 | 35 | .user-input { 36 | background-color: var(--bg-screen); 37 | color: var(--text-color); 38 | } 39 | 40 | .grid-container { 41 | background-color: var(--bg-toggle-keypad); 42 | } 43 | 44 | .grid-container>button { 45 | background-color: var(--bg-keys); 46 | color: var(--text-color); 47 | box-shadow: 0 5px var(--key-shadow-keys); 48 | } 49 | 50 | button:nth-child(17), 51 | button:nth-child(4) { 52 | background-color: var(--bg-del-reset-key); 53 | box-shadow: 0 5px var(--key-shadow-del-reset); 54 | color: var(--bg-keys); 55 | } 56 | 57 | button:nth-child(18) { 58 | background-color: var(--bg-result-toggle-key); 59 | box-shadow: 0 5px var(--key-shadow-result); 60 | color: white; 61 | } -------------------------------------------------------------------------------- /css/theme2.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --bg-theme: hsl(268, 75%, 9%); 3 | --bg-toggle-keypad: hsl(268, 71%, 12%); 4 | --bg-del-reset-key: hsl(268, 47%, 21%); 5 | --key-shadow-del-reset: hsl(290, 70%, 36%); 6 | --bg-keys: hsl(281, 89%, 26%); 7 | --key-shadow-keys: hsl(285, 91%, 52%); 8 | --bg-result-toggle-key: hsl(176, 100%, 44%); 9 | --key-shadow-result: hsl(177, 92%, 70%); 10 | --text-color: hsl(52, 100%, 62%); 11 | --text-del-result-color: hsl(0, 0, 100%); 12 | --text-result-color: hsl(198, 20%, 13%); 13 | } 14 | 15 | body { 16 | background-color: var(--bg-theme); 17 | } 18 | 19 | label, 20 | h6 { 21 | color: var(--text-color); 22 | } 23 | 24 | .header>h1 { 25 | color: var(--text-color); 26 | } 27 | 28 | .input { 29 | background-color: var(--bg-toggle-keypad); 30 | } 31 | 32 | input:checked { 33 | background-color: var(--bg-result-toggle-key); 34 | } 35 | 36 | .user-input { 37 | background-color: var(--bg-toggle-keypad); 38 | color: var(--text-color); 39 | } 40 | 41 | .grid-container { 42 | background-color: var(--bg-toggle-keypad); 43 | } 44 | 45 | .grid-container>button { 46 | background-color: var(--bg-keys); 47 | color: var(--text-color); 48 | box-shadow: 0 5px var(--key-shadow-keys); 49 | } 50 | 51 | button:nth-child(17), 52 | button:nth-child(4) { 53 | background-color: var(--bg-del-reset-key); 54 | box-shadow: 0 5px var(--key-shadow-del-reset); 55 | color: white; 56 | } 57 | 58 | button:nth-child(18) { 59 | background-color: var(--bg-result-toggle-key); 60 | box-shadow: 0 5px var(--key-shadow-result); 61 | color: var(--text-result-color) 62 | } -------------------------------------------------------------------------------- /design/active-states-theme-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/active-states-theme-1.jpg -------------------------------------------------------------------------------- /design/active-states-theme-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/active-states-theme-2.jpg -------------------------------------------------------------------------------- /design/active-states-theme-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/active-states-theme-3.jpg -------------------------------------------------------------------------------- /design/desktop-design-theme-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/desktop-design-theme-1.jpg -------------------------------------------------------------------------------- /design/desktop-design-theme-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/desktop-design-theme-2.jpg -------------------------------------------------------------------------------- /design/desktop-design-theme-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/desktop-design-theme-3.jpg -------------------------------------------------------------------------------- /design/desktop-preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/desktop-preview.jpg -------------------------------------------------------------------------------- /design/mobile-design-theme-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/mobile-design-theme-1.jpg -------------------------------------------------------------------------------- /design/mobile-design-theme-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/mobile-design-theme-2.jpg -------------------------------------------------------------------------------- /design/mobile-design-theme-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/design/mobile-design-theme-3.jpg -------------------------------------------------------------------------------- /images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/Calculator-app_frontend_project/b35428a4bedec3a4fba1d7e5ec6f2535e26134ab/images/favicon-32x32.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Calculator app 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |
19 |

calc

20 |
THEME
21 |
22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
58 |
59 | 60 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | const links = document.querySelectorAll("link"); 2 | const toggleBtn = document.querySelectorAll("input"); 3 | const prevOperandText = document.querySelector("[data-previous-operand]"); 4 | const currentOperandText = document.querySelector("[data-current-operand]"); 5 | const deleteBtn = document.querySelector("[data-delete]"); 6 | const resultBtn = document.querySelector("[data-output]"); 7 | const resetBtn = document.querySelector("[data-reset]"); 8 | const operands = document.querySelectorAll("[data-num]"); 9 | const operatorBtn = document.querySelectorAll("[data-operator]"); 10 | let prevOperand = prevOperandText.innerText; 11 | let currentOperand = currentOperandText.innerText; 12 | let operation; 13 | 14 | function themeChange(i) { 15 | if(i === "0"){ 16 | links[2].setAttribute("href", ""); 17 | } else { 18 | links[2].setAttribute("href", `css/theme${i}.css`); 19 | } 20 | } 21 | 22 | function reset() { 23 | prevOperand = ""; 24 | currentOperand = ""; 25 | operation = undefined; 26 | } 27 | 28 | function deleteOperand() { 29 | currentOperand = currentOperand.toString().slice(0, -1); 30 | } 31 | 32 | function addNumber(number) { 33 | if(number === "." && currentOperand.includes(".")) return; 34 | currentOperand = currentOperand.toString() + number.toString(); 35 | } 36 | 37 | function operationSelection(operate) { 38 | if(currentOperandText === "") return; 39 | if(prevOperandText !== "") { 40 | calculatorOperation(); 41 | } 42 | operation = operate; 43 | prevOperand = currentOperand; 44 | currentOperand = ""; 45 | } 46 | 47 | function calculatorOperation() { 48 | let result; 49 | let prev = parseFloat(prevOperand); 50 | let current = parseFloat(currentOperand); 51 | if(isNaN(prev) || isNaN(current)) return; 52 | 53 | switch(operation){ 54 | case "+": 55 | result = prev + current; 56 | break; 57 | 58 | case "-": 59 | result = prev - current 60 | break; 61 | 62 | case "*": 63 | result = prev * current; 64 | break; 65 | 66 | case "/": 67 | result = prev / current; 68 | break; 69 | 70 | default: 71 | return; 72 | } 73 | currentOperand = result; 74 | operation = undefined; 75 | prevOperand = ""; 76 | prevOperandText.innerText = ""; 77 | } 78 | 79 | function displayNum() { 80 | currentOperandText.innerText = currentOperand.toLocaleString("en"); 81 | if(operation !== undefined) { 82 | prevOperandText.innerText = `${prevOperand} ${operation.toString("en")}`; 83 | } else { 84 | prevOperandText.innerText = prevOperand; 85 | } 86 | } 87 | 88 | toggleBtn.forEach(btn => { 89 | btn.addEventListener("click", () => { 90 | themeChange(btn.value); 91 | }); 92 | }) 93 | 94 | resetBtn.addEventListener("click", () => { 95 | reset(); 96 | displayNum(); 97 | }); 98 | 99 | deleteBtn.addEventListener("click", () => { 100 | deleteOperand(); 101 | displayNum(); 102 | }); 103 | 104 | operands.forEach(operand => { 105 | operand.addEventListener("click", () => { 106 | addNumber(operand.innerText); 107 | displayNum(); 108 | }); 109 | }); 110 | 111 | operatorBtn.forEach(btn => { 112 | btn.addEventListener("click", () => { 113 | operationSelection(btn.innerText); 114 | displayNum(); 115 | }) 116 | }) 117 | 118 | resultBtn.addEventListener("click", () => { 119 | calculatorOperation(); 120 | displayNum(); 121 | }); 122 | -------------------------------------------------------------------------------- /style-guide.md: -------------------------------------------------------------------------------- 1 | # Front-end Style Guide 2 | 3 | ## Layout 4 | 5 | The designs were created to the following widths: 6 | 7 | - Mobile: 375px 8 | - Desktop: 1440px 9 | 10 | ## Colors 11 | 12 | ### Theme 1 13 | 14 | #### Backgrounds 15 | 16 | - Very dark desaturated blue (main background): hsl(222, 26%, 31%) 17 | - Very dark desaturated blue (toggle background, keypad background): hsl(223, 31%, 20%) 18 | - Very dark desaturated blue (screen background): hsl(224, 36%, 15%) 19 | 20 | #### Keys 21 | 22 | - Desaturated dark blue (key background): hsl(225, 21%, 49%) 23 | - Desaturated dark blue (key shadow): hsl(224, 28%, 35%) 24 | 25 | - Red (key background, toggle): hsl(6, 63%, 50%) 26 | - Dark red (key shadow): hsl(6, 70%, 34%) 27 | 28 | - Light grayish orange (key background): hsl(30, 25%, 89%) 29 | - Grayish orange (key shadow): hsl(28, 16%, 65%) 30 | 31 | #### Text 32 | 33 | - Very dark grayish blue: hsl(221, 14%, 31%) 34 | - White: hsl(0, 0%, 100%) 35 | 36 | ### Theme 2 37 | 38 | #### Backgrounds 39 | 40 | - Light gray (main background): hsl(0, 0%, 90%) 41 | - Grayish red (toggle background, keypad background): hsl(0, 5%, 81%) 42 | - Very light gray (screen background): hsl(0, 0%, 93%) 43 | 44 | #### Keys 45 | 46 | - Dark moderate cyan (key background): hsl(185, 42%, 37%) 47 | - Very dark cyan (key shadow): hsl(185, 58%, 25%) 48 | 49 | - Orange (key background, toggle): hsl(25, 98%, 40%) 50 | - Dark orange (key shadow): hsl(25, 99%, 27%) 51 | 52 | - Light grayish yellow (key background): hsl(45, 7%, 89%) 53 | - Dark grayish orange (key shadow): hsl(35, 11%, 61%) 54 | 55 | #### Text 56 | 57 | - Very dark grayish yellow: hsl(60, 10%, 19%) 58 | - White (text): hsl(0, 0%, 100%) 59 | 60 | ### Theme 3 61 | 62 | #### Backgrounds 63 | 64 | - Very dark violet (main background): hsl(268, 75%, 9%) 65 | - Very dark violet (toggle background, keypad background, screen background): hsl(268, 71%, 12%) 66 | 67 | #### Keys 68 | 69 | - Dark violet (key background): hsl(281, 89%, 26%) 70 | - Vivid magenta (key shadow): hsl(285, 91%, 52%) 71 | 72 | - Pure cyan (key background, toggle): hsl(176, 100%, 44%) 73 | - Soft cyan (key shadow): hsl(177, 92%, 70%) 74 | 75 | - Very dark violet (key background): hsl(268, 47%, 21%) 76 | - Dark magenta (key shadow): hsl(290, 70%, 36%) 77 | 78 | #### Text 79 | 80 | - Light yellow: hsl(52, 100%, 62%) 81 | - Very dark blue: hsl(198, 20%, 13%) 82 | - White (text): hsl(0, 0%, 100%) 83 | 84 | ## Typography 85 | 86 | ### Body Copy 87 | 88 | - Font size (numbers): 32px 89 | 90 | ### Font 91 | 92 | - Family: [League Spartan](https://fonts.google.com/specimen/League+Spartan) 93 | - Weights: 700 94 | --------------------------------------------------------------------------------