├── img ├── subtle_white_feathers │ ├── subtle_white_feathers.png │ ├── subtle_white_feathers_@2X.png │ └── readme.txt ├── minus-solid-white.svg ├── equals-solid-white.svg ├── equals-solid-gray.svg ├── equals-solid-teal.svg ├── plus-solid-white.svg ├── divide-solid-white.svg ├── times-solid-white.svg ├── backspace-solid-white.svg ├── backspace-solid-teal.svg ├── github-white.svg ├── github-gray.svg └── github-orange.svg ├── README.md ├── css ├── reset.css ├── stylesNoPreFix.css └── styles.css ├── index.html └── script.js /img/subtle_white_feathers/subtle_white_feathers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rlmoser99/calculator/HEAD/img/subtle_white_feathers/subtle_white_feathers.png -------------------------------------------------------------------------------- /img/subtle_white_feathers/subtle_white_feathers_@2X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rlmoser99/calculator/HEAD/img/subtle_white_feathers/subtle_white_feathers_@2X.png -------------------------------------------------------------------------------- /img/subtle_white_feathers/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | ======================================================== 4 | This pattern is downloaded from www.subtlepatterns.com 5 | If you need more, that's where to get'em. 6 | ======================================================== 7 | 8 | -------------------------------------------------------------------------------- /img/minus-solid-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/equals-solid-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/equals-solid-gray.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/equals-solid-teal.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/plus-solid-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/divide-solid-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/times-solid-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Calculator 2 | This project is from [The Odin Project](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/calculator). This project was completed before TOP clarified the instructions to only evaluate a single pair of numbers at a time. **If you are doing TOP, do not attempt to re-create this functionality!** 3 | 4 | ## Code, Re-Factor, Repeat... 5 | I had to re-factor my work several times as I realized how different functions and variables interacted with each other. I hope to learn more on how to plan and execute a project like this more efficiently. As I am learning, I just took everything one step at time and then re-factor when necessary. 6 | 7 | ## Regex is AMAZING! 8 | I really enjoyed working with regular expressions and probably over-used them to format the display numbers. 9 | 10 | ## Order of Operations 11 | The calculator is not 100% scientifically accurate. Although, I did use the order of operations published by [Wolfram](http://mathworld.wolfram.com/Precedence.html): 12 | 1. Parenthesis 13 | 2. Factorial 14 | 3. Exponentiation 15 | 4. Multiplication and division 16 | 5. Addition and subtraction 17 | -------------------------------------------------------------------------------- /img/backspace-solid-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/backspace-solid-teal.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /css/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ 2 | v2.0 | 20110126 3 | License: none (public domain) 4 | */ 5 | 6 | html, body, div, span, applet, object, iframe, 7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 8 | a, abbr, acronym, address, big, cite, code, 9 | del, dfn, em, img, ins, kbd, q, s, samp, 10 | small, strike, strong, sub, sup, tt, var, 11 | b, u, i, center, 12 | dl, dt, dd, ol, ul, li, 13 | fieldset, form, label, legend, 14 | table, caption, tbody, tfoot, thead, tr, th, td, 15 | article, aside, canvas, details, embed, 16 | figure, figcaption, footer, header, hgroup, 17 | menu, nav, output, ruby, section, summary, 18 | time, mark, audio, video { 19 | margin: 0; 20 | padding: 0; 21 | border: 0; 22 | font-size: 100%; 23 | font: inherit; 24 | vertical-align: baseline; 25 | } 26 | /* HTML5 display-role reset for older browsers */ 27 | article, aside, details, figcaption, figure, 28 | footer, header, hgroup, menu, nav, section { 29 | display: block; 30 | } 31 | body { 32 | line-height: 1; 33 | } 34 | ol, ul { 35 | list-style: none; 36 | } 37 | blockquote, q { 38 | quotes: none; 39 | } 40 | blockquote:before, blockquote:after, 41 | q:before, q:after { 42 | content: ''; 43 | content: none; 44 | } 45 | table { 46 | border-collapse: collapse; 47 | border-spacing: 0; 48 | } -------------------------------------------------------------------------------- /img/github-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/github-gray.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /img/github-orange.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Calculator 12 | 13 | 14 | 15 | 16 |
17 |

Calculator

18 |

19 | This project was completed before TOP clarified the instructions to only evaluate a single pair of numbers 20 | at a time. 21 |

22 |

If you are doing TOP, do not attempt to re-create this functionality!

23 |
24 | 25 |
26 |
27 |
28 |
29 |
30 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | 57 |
58 | 59 |
60 |

61 |
62 |
63 | 72 |
73 | 74 | 75 | -------------------------------------------------------------------------------- /css/stylesNoPreFix.css: -------------------------------------------------------------------------------- 1 | html { 2 | box-sizing: border-box; 3 | } 4 | 5 | body { 6 | background-color: #273043; 7 | font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; 8 | } 9 | 10 | .wrapper { 11 | display: flex; 12 | flex-direction: column; 13 | justify-content: flex-start; 14 | min-height: 100vh; 15 | } 16 | 17 | .wrapper > * { 18 | flex: 0 1 auto; 19 | } 20 | 21 | .calculator-wrapper { 22 | flex: 1 1 auto; 23 | } 24 | 25 | .container { 26 | background-color: #242c3d; 27 | border: 1px solid black; 28 | box-shadow: 3px 3px 3px black; 29 | display: grid; 30 | grid-gap: 4px; 31 | grid-template-columns: repeat(4, 1fr); 32 | grid-template-rows: 35px repeat(6, 1fr); 33 | height: 90vw; 34 | margin: 30px auto; 35 | max-height: 400px; 36 | max-width: 400px; 37 | width: 80vw; 38 | } 39 | 40 | .container > * { 41 | align-items: center; 42 | background-color: #242c3d; 43 | border: none; 44 | color: #00b1c5; 45 | display: grid; 46 | font-family: monospace; 47 | font-size: 1.5rem; 48 | font-weight: 600; 49 | justify-content: center; 50 | } 51 | 52 | /* Display Areas */ 53 | .display-container{ 54 | align-items: center; 55 | background-color: #00b1c5; 56 | display: grid; 57 | grid-column: 1 / 4; 58 | grid-row: 1 / 3; 59 | grid-template-columns: repeat(3, 1fr); 60 | grid-template-rows: 35px auto; 61 | justify-content: center; 62 | } 63 | 64 | .display, .raw-display { 65 | font-family: monospace; 66 | justify-content: right; 67 | justify-self: stretch; 68 | overflow: scroll; 69 | padding: 0 10px; 70 | text-align: end; 71 | } 72 | 73 | .display { 74 | color: #273043; 75 | font-size: 1.5rem; 76 | grid-column: 1 / 4; 77 | grid-row: 2 / 3; 78 | } 79 | 80 | .raw-display { 81 | color: white; 82 | font-size: .65rem; 83 | grid-column: 1 / 4; 84 | grid-row: 1 / 2; 85 | } 86 | 87 | /* Buttons */ 88 | button { 89 | overflow: hidden; 90 | } 91 | 92 | button img { 93 | margin: 0 auto; 94 | } 95 | 96 | button sup { 97 | font-size: .5rem; 98 | height: 30px; 99 | vertical-align: top; 100 | } 101 | 102 | button:focus { 103 | outline-color: #00b1c5; 104 | } 105 | 106 | button:hover { 107 | color: #00cfe6; 108 | font-size: 1.75rem; 109 | } 110 | 111 | .operator { 112 | background: #242c3d; 113 | color: white; 114 | font-family: inherit; 115 | font-size: 1.25rem; 116 | } 117 | 118 | .operator:focus, 119 | .operator:hover { 120 | color: white; 121 | font-size: 1.5rem; 122 | } 123 | 124 | .operator:focus img, 125 | .operator:hover img { 126 | height: 25px; 127 | } 128 | 129 | #Backspace { 130 | grid-column: 4 / 5; 131 | grid-row: 1 / 3; 132 | } 133 | 134 | #Backspace:focus img, 135 | #Backspace:hover img { 136 | height: 35px; 137 | } 138 | 139 | .equal { 140 | background-color: #00b1c5; 141 | } 142 | 143 | .equal:focus{ 144 | outline-color: white; 145 | } 146 | 147 | #exponent { 148 | display: flex; 149 | } 150 | 151 | #factorial, #exponent { 152 | letter-spacing: .1em; 153 | } 154 | 155 | /* Text Content */ 156 | h1 { 157 | color: #ff7800; 158 | font-size: 2rem; 159 | margin: 30px 0 0; 160 | text-align: center; 161 | } 162 | 163 | p { 164 | color: #ff7800; 165 | font-size: .9rem; 166 | line-height: 1.5rem; 167 | } 168 | 169 | p span { 170 | color: white; 171 | } 172 | 173 | .warning-container { 174 | margin: 15px auto; 175 | max-width: 400px; 176 | min-height: 125px; 177 | width: 80vw; 178 | } 179 | 180 | .shortcut { 181 | align-items: center; 182 | display: flex; 183 | } 184 | 185 | .shortcut img { 186 | padding-right: 6px; 187 | } 188 | 189 | /* Footer */ 190 | footer { 191 | align-items: center; 192 | background-color: #00b1c5; 193 | display: flex; 194 | height: 50px; 195 | justify-content: space-between; 196 | justify-self: flex-end; 197 | padding: 5px; 198 | width: 100%; 199 | } 200 | 201 | footer img { 202 | margin-right: 15px; 203 | } 204 | 205 | .description { 206 | color: white; 207 | font-size: .9rem; 208 | line-height: 20px; 209 | margin-left: 15px; 210 | width: 60vw; 211 | } 212 | 213 | a { 214 | color: white; 215 | } 216 | 217 | a:hover { 218 | color: #242c3d; 219 | } 220 | 221 | @media only screen and (min-width: 400px) { 222 | .container > * { 223 | font-size: 2.25rem; 224 | } 225 | 226 | .display { 227 | font-size: 1.9rem; 228 | } 229 | 230 | .raw-display { 231 | font-size: .9rem; 232 | } 233 | 234 | button sup { 235 | font-size: .7rem; 236 | } 237 | 238 | .operator { 239 | font-size: 1.5rem; 240 | } 241 | 242 | button img { 243 | height: 25px; 244 | } 245 | 246 | button:hover { 247 | font-size: 2.5rem; 248 | } 249 | 250 | #Backspace img { 251 | height: 35px; 252 | } 253 | 254 | #Backspace:focus img, 255 | #Backspace:hover img { 256 | height: 40px; 257 | } 258 | 259 | .operator:hover img { 260 | height: 30px; 261 | } 262 | 263 | .operator:focus, 264 | .operator:hover { 265 | font-size: 1.75rem; 266 | } 267 | 268 | #positive-negative { 269 | font-size: 1.75rem; 270 | } 271 | 272 | #positive-negative:hover { 273 | font-size: 2rem; 274 | } 275 | 276 | h1 { 277 | font-size: 2.25rem; 278 | } 279 | 280 | p { 281 | font-size: 1rem; 282 | /* line-height: 1.75rem; */ 283 | } 284 | } 285 | 286 | @media only screen and (min-width: 500px) { 287 | 288 | .container > * { 289 | font-size: 3rem; 290 | } 291 | 292 | .display { 293 | font-size: 2.4rem; 294 | } 295 | 296 | .raw-display { 297 | font-size: 1.1rem; 298 | } 299 | 300 | button sup { 301 | font-size: .9rem; 302 | } 303 | 304 | .operator { 305 | font-size: 1.75rem; 306 | } 307 | 308 | button img { 309 | height: 30px; 310 | } 311 | 312 | .operator:hover img { 313 | height: 35px; 314 | } 315 | 316 | #Backspace img { 317 | height: 40px; 318 | } 319 | 320 | #Backspace:focus img, 321 | #Backspace:hover img { 322 | height: 45px; 323 | } 324 | 325 | button:hover { 326 | font-size: 3.25rem; 327 | } 328 | 329 | .operator:focus, 330 | .operator:hover { 331 | font-size: 2rem; 332 | } 333 | 334 | #positive-negative { 335 | font-size: 2.25rem; 336 | } 337 | 338 | #positive-negative:hover { 339 | font-size: 2.5rem; 340 | } 341 | 342 | h1 { 343 | font-size: 2.5rem; 344 | } 345 | 346 | p { 347 | font-size: 1.25rem; 348 | line-height: 1.75rem; 349 | } 350 | 351 | footer img { 352 | margin-right: 30px; 353 | } 354 | 355 | .description { 356 | margin-left: 30px; 357 | } 358 | } -------------------------------------------------------------------------------- /css/styles.css: -------------------------------------------------------------------------------- 1 | /* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.26, autoprefixer: v9.7.3) */ 2 | 3 | html { 4 | -webkit-box-sizing: border-box; 5 | box-sizing: border-box; 6 | } 7 | 8 | body { 9 | background-color: #273043; 10 | font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; 11 | } 12 | 13 | .wrapper { 14 | display: -webkit-box; 15 | display: -ms-flexbox; 16 | display: flex; 17 | -webkit-box-orient: vertical; 18 | -webkit-box-direction: normal; 19 | -ms-flex-direction: column; 20 | flex-direction: column; 21 | -webkit-box-pack: start; 22 | -ms-flex-pack: start; 23 | justify-content: flex-start; 24 | min-height: 100vh; 25 | overflow: hidden; 26 | 27 | } 28 | 29 | .wrapper > * { 30 | -webkit-box-flex: 0; 31 | -ms-flex: 0 1 auto; 32 | flex: 0 1 auto; 33 | } 34 | 35 | .calculator-wrapper { 36 | -webkit-box-flex: 1; 37 | -ms-flex: 1 1 auto; 38 | flex: 1 1 auto; 39 | } 40 | 41 | .container { 42 | background-color: #242c3d; 43 | border: 1px solid black; 44 | -webkit-box-shadow: 3px 3px 3px black; 45 | box-shadow: 3px 3px 3px black; 46 | display: -ms-grid; 47 | display: grid; 48 | grid-gap: 4px; 49 | -ms-grid-columns: 1fr 4px 1fr 4px 1fr 4px 1fr; 50 | grid-template-columns: repeat(4, 1fr); 51 | -ms-grid-rows: 35px 4px 1fr 4px 1fr 4px 1fr 4px 1fr 4px 1fr 4px 1fr; 52 | grid-template-rows: 35px repeat(6, 1fr); 53 | height: 90vw; 54 | margin: 30px auto; 55 | max-height: 400px; 56 | max-width: 400px; 57 | width: 80vw; 58 | } 59 | 60 | .container > *:nth-child(1) { 61 | -ms-grid-row: 1; 62 | -ms-grid-column: 1; 63 | } 64 | 65 | .container > *:nth-child(2) { 66 | -ms-grid-row: 1; 67 | -ms-grid-column: 3; 68 | } 69 | 70 | .container > *:nth-child(3) { 71 | -ms-grid-row: 1; 72 | -ms-grid-column: 5; 73 | } 74 | 75 | .container > *:nth-child(4) { 76 | -ms-grid-row: 1; 77 | -ms-grid-column: 7; 78 | } 79 | 80 | .container > *:nth-child(5) { 81 | -ms-grid-row: 3; 82 | -ms-grid-column: 1; 83 | } 84 | 85 | .container > *:nth-child(6) { 86 | -ms-grid-row: 3; 87 | -ms-grid-column: 3; 88 | } 89 | 90 | .container > *:nth-child(7) { 91 | -ms-grid-row: 3; 92 | -ms-grid-column: 5; 93 | } 94 | 95 | .container > *:nth-child(8) { 96 | -ms-grid-row: 3; 97 | -ms-grid-column: 7; 98 | } 99 | 100 | .container > *:nth-child(9) { 101 | -ms-grid-row: 5; 102 | -ms-grid-column: 1; 103 | } 104 | 105 | .container > *:nth-child(10) { 106 | -ms-grid-row: 5; 107 | -ms-grid-column: 3; 108 | } 109 | 110 | .container > *:nth-child(11) { 111 | -ms-grid-row: 5; 112 | -ms-grid-column: 5; 113 | } 114 | 115 | .container > *:nth-child(12) { 116 | -ms-grid-row: 5; 117 | -ms-grid-column: 7; 118 | } 119 | 120 | .container > *:nth-child(13) { 121 | -ms-grid-row: 7; 122 | -ms-grid-column: 1; 123 | } 124 | 125 | .container > *:nth-child(14) { 126 | -ms-grid-row: 7; 127 | -ms-grid-column: 3; 128 | } 129 | 130 | .container > *:nth-child(15) { 131 | -ms-grid-row: 7; 132 | -ms-grid-column: 5; 133 | } 134 | 135 | .container > *:nth-child(16) { 136 | -ms-grid-row: 7; 137 | -ms-grid-column: 7; 138 | } 139 | 140 | .container > *:nth-child(17) { 141 | -ms-grid-row: 9; 142 | -ms-grid-column: 1; 143 | } 144 | 145 | .container > *:nth-child(18) { 146 | -ms-grid-row: 9; 147 | -ms-grid-column: 3; 148 | } 149 | 150 | .container > *:nth-child(19) { 151 | -ms-grid-row: 9; 152 | -ms-grid-column: 5; 153 | } 154 | 155 | .container > *:nth-child(20) { 156 | -ms-grid-row: 9; 157 | -ms-grid-column: 7; 158 | } 159 | 160 | .container > *:nth-child(21) { 161 | -ms-grid-row: 11; 162 | -ms-grid-column: 1; 163 | } 164 | 165 | .container > *:nth-child(22) { 166 | -ms-grid-row: 11; 167 | -ms-grid-column: 3; 168 | } 169 | 170 | .container > *:nth-child(23) { 171 | -ms-grid-row: 11; 172 | -ms-grid-column: 5; 173 | } 174 | 175 | .container > *:nth-child(24) { 176 | -ms-grid-row: 11; 177 | -ms-grid-column: 7; 178 | } 179 | 180 | .container > *:nth-child(25) { 181 | -ms-grid-row: 13; 182 | -ms-grid-column: 1; 183 | } 184 | 185 | .container > *:nth-child(26) { 186 | -ms-grid-row: 13; 187 | -ms-grid-column: 3; 188 | } 189 | 190 | .container > *:nth-child(27) { 191 | -ms-grid-row: 13; 192 | -ms-grid-column: 5; 193 | } 194 | 195 | .container > *:nth-child(28) { 196 | -ms-grid-row: 13; 197 | -ms-grid-column: 7; 198 | } 199 | 200 | .container > * { 201 | -webkit-box-align: center; 202 | -ms-flex-align: center; 203 | align-items: center; 204 | background-color: #242c3d; 205 | border: none; 206 | color: #00b1c5; 207 | display: -ms-grid; 208 | display: grid; 209 | font-family: monospace; 210 | font-size: 1.5rem; 211 | font-weight: 600; 212 | -webkit-box-pack: center; 213 | -ms-flex-pack: center; 214 | justify-content: center; 215 | } 216 | 217 | /* Display Areas */ 218 | .display-container{ 219 | -webkit-box-align: center; 220 | -ms-flex-align: center; 221 | align-items: center; 222 | background-color: #00b1c5; 223 | display: -ms-grid; 224 | display: grid; 225 | -ms-grid-column: 1; 226 | -ms-grid-column-span: 3; 227 | grid-column: 1 / 4; 228 | -ms-grid-row: 1; 229 | -ms-grid-row-span: 2; 230 | grid-row: 1 / 3; 231 | -ms-grid-columns: (1fr)[3]; 232 | grid-template-columns: repeat(3, 1fr); 233 | -ms-grid-rows: 35px auto; 234 | grid-template-rows: 35px auto; 235 | -webkit-box-pack: center; 236 | -ms-flex-pack: center; 237 | justify-content: center; 238 | } 239 | .display-container > *:nth-child(1){ 240 | -ms-grid-row: 1; 241 | -ms-grid-column: 1; 242 | } 243 | .display-container > *:nth-child(2){ 244 | -ms-grid-row: 1; 245 | -ms-grid-column: 2; 246 | } 247 | .display-container > *:nth-child(3){ 248 | -ms-grid-row: 1; 249 | -ms-grid-column: 3; 250 | } 251 | .display-container > *:nth-child(4){ 252 | -ms-grid-row: 2; 253 | -ms-grid-column: 1; 254 | } 255 | .display-container > *:nth-child(5){ 256 | -ms-grid-row: 2; 257 | -ms-grid-column: 2; 258 | } 259 | .display-container > *:nth-child(6){ 260 | -ms-grid-row: 2; 261 | -ms-grid-column: 3; 262 | } 263 | 264 | .display, .raw-display { 265 | font-family: monospace; 266 | -webkit-box-pack: right; 267 | -ms-flex-pack: right; 268 | justify-content: right; 269 | -ms-grid-column-align: stretch; 270 | justify-self: stretch; 271 | overflow: hidden; 272 | padding: 0 10px; 273 | text-align: end; 274 | } 275 | 276 | .display { 277 | color: #273043; 278 | font-size: 1.5rem; 279 | -ms-grid-column: 1; 280 | -ms-grid-column-span: 3; 281 | grid-column: 1 / 4; 282 | -ms-grid-row: 2; 283 | -ms-grid-row-span: 1; 284 | grid-row: 2 / 3; 285 | } 286 | 287 | .raw-display { 288 | color: white; 289 | font-size: .65rem; 290 | -ms-grid-column: 1; 291 | -ms-grid-column-span: 3; 292 | grid-column: 1 / 4; 293 | -ms-grid-row: 1; 294 | -ms-grid-row-span: 1; 295 | grid-row: 1 / 2; 296 | } 297 | 298 | /* Buttons */ 299 | button { 300 | overflow: hidden; 301 | } 302 | 303 | button img { 304 | margin: 0 auto; 305 | } 306 | 307 | button sup { 308 | font-size: .5rem; 309 | height: 30px; 310 | vertical-align: top; 311 | } 312 | 313 | button:focus { 314 | outline-color: #00b1c5; 315 | } 316 | 317 | button:hover { 318 | color: #00cfe6; 319 | font-size: 1.75rem; 320 | } 321 | 322 | .operator { 323 | background: #242c3d; 324 | color: white; 325 | font-family: inherit; 326 | font-size: 1.25rem; 327 | } 328 | 329 | .operator:focus, 330 | .operator:hover { 331 | color: white; 332 | font-size: 1.5rem; 333 | } 334 | 335 | .operator:focus img, 336 | .operator:hover img { 337 | height: 25px; 338 | } 339 | 340 | #Backspace { 341 | -ms-grid-column: 4; 342 | -ms-grid-column-span: 1; 343 | grid-column: 4 / 5; 344 | -ms-grid-row: 1; 345 | -ms-grid-row-span: 2; 346 | grid-row: 1 / 3; 347 | } 348 | 349 | #Backspace:focus img, 350 | #Backspace:hover img { 351 | height: 35px; 352 | } 353 | 354 | .equal { 355 | background-color: #00b1c5; 356 | } 357 | 358 | .equal:focus{ 359 | outline-color: white; 360 | } 361 | 362 | #exponent { 363 | display: -webkit-box; 364 | display: -ms-flexbox; 365 | display: flex; 366 | } 367 | 368 | #factorial, #exponent { 369 | letter-spacing: .1em; 370 | } 371 | 372 | /* Text Content */ 373 | h1 { 374 | color: #ff7800; 375 | font-size: 2rem; 376 | margin: 30px 0 0; 377 | text-align: center; 378 | } 379 | 380 | h2 { 381 | color: #ffffff; 382 | margin: 15px 5vw; 383 | text-align: center; 384 | } 385 | 386 | p { 387 | color: #ff7800; 388 | font-size: .9rem; 389 | line-height: 1.5rem; 390 | } 391 | 392 | p span { 393 | color: white; 394 | } 395 | 396 | .warning-container { 397 | margin: 15px auto; 398 | max-width: 400px; 399 | min-height: 125px; 400 | width: 80vw; 401 | } 402 | 403 | .shortcut { 404 | -webkit-box-align: center; 405 | -ms-flex-align: center; 406 | align-items: center; 407 | display: -webkit-box; 408 | display: -ms-flexbox; 409 | display: flex; 410 | } 411 | 412 | .shortcut img { 413 | padding-right: 6px; 414 | } 415 | 416 | /* Footer */ 417 | footer { 418 | -webkit-box-align: center; 419 | -ms-flex-align: center; 420 | align-items: center; 421 | background-color: #00b1c5; 422 | display: -webkit-box; 423 | display: -ms-flexbox; 424 | display: flex; 425 | height: 50px; 426 | -webkit-box-pack: justify; 427 | -ms-flex-pack: justify; 428 | justify-content: space-between; 429 | justify-self: flex-end; 430 | padding: 5px; 431 | width: 100%; 432 | } 433 | 434 | footer img { 435 | margin-right: 15px; 436 | } 437 | 438 | .description { 439 | color: white; 440 | font-size: .9rem; 441 | line-height: 20px; 442 | margin-left: 15px; 443 | width: 60vw; 444 | } 445 | 446 | a { 447 | color: white; 448 | } 449 | 450 | a:hover { 451 | color: #242c3d; 452 | } 453 | 454 | @media only screen and (min-width: 400px) { 455 | .container > * { 456 | font-size: 2.25rem; 457 | } 458 | 459 | .display { 460 | font-size: 1.9rem; 461 | } 462 | 463 | .raw-display { 464 | font-size: .9rem; 465 | } 466 | 467 | button sup { 468 | font-size: .7rem; 469 | } 470 | 471 | .operator { 472 | font-size: 1.5rem; 473 | } 474 | 475 | button img { 476 | height: 25px; 477 | } 478 | 479 | button:hover { 480 | font-size: 2.5rem; 481 | } 482 | 483 | #Backspace img { 484 | height: 35px; 485 | } 486 | 487 | #Backspace:focus img, 488 | #Backspace:hover img { 489 | height: 40px; 490 | } 491 | 492 | .operator:hover img { 493 | height: 30px; 494 | } 495 | 496 | .operator:focus, 497 | .operator:hover { 498 | font-size: 1.75rem; 499 | } 500 | 501 | #positive-negative { 502 | font-size: 1.75rem; 503 | } 504 | 505 | #positive-negative:hover { 506 | font-size: 2rem; 507 | } 508 | 509 | h1 { 510 | font-size: 2.25rem; 511 | } 512 | 513 | p { 514 | font-size: 1rem; 515 | /* line-height: 1.75rem; */ 516 | } 517 | } 518 | 519 | @media only screen and (min-width: 500px) { 520 | 521 | .container > * { 522 | font-size: 3rem; 523 | } 524 | 525 | .display { 526 | font-size: 2.4rem; 527 | } 528 | 529 | .raw-display { 530 | font-size: 1.1rem; 531 | } 532 | 533 | button sup { 534 | font-size: .9rem; 535 | } 536 | 537 | .operator { 538 | font-size: 1.75rem; 539 | } 540 | 541 | button img { 542 | height: 30px; 543 | } 544 | 545 | .operator:hover img { 546 | height: 35px; 547 | } 548 | 549 | #Backspace img { 550 | height: 40px; 551 | } 552 | 553 | #Backspace:focus img, 554 | #Backspace:hover img { 555 | height: 45px; 556 | } 557 | 558 | button:hover { 559 | font-size: 3.25rem; 560 | } 561 | 562 | .operator:focus, 563 | .operator:hover { 564 | font-size: 2rem; 565 | } 566 | 567 | #positive-negative { 568 | font-size: 2.25rem; 569 | } 570 | 571 | #positive-negative:hover { 572 | font-size: 2.5rem; 573 | } 574 | 575 | h1 { 576 | font-size: 2.5rem; 577 | } 578 | 579 | p { 580 | font-size: 1.25rem; 581 | line-height: 1.75rem; 582 | } 583 | 584 | footer img { 585 | margin-right: 30px; 586 | } 587 | 588 | .description { 589 | margin-left: 30px; 590 | } 591 | } -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | const calcButtons = document.querySelectorAll('button'); 2 | const display = document.querySelector('.display'); 3 | const rawDisplay = document.querySelector('.raw-display'); 4 | const warning = document.querySelector('.warning') 5 | const footerIcon = document.querySelector('footer img'); 6 | let displayNumber = ''; 7 | let rawData = ''; 8 | let rawDataResult = ''; 9 | let removeDigits = ''; 10 | let oldNotation = ''; 11 | let formattedRawDataArray = []; 12 | 13 | function add(a, b) { 14 | return a + b; 15 | } 16 | 17 | function subtract(a, b) { 18 | return a - b; 19 | } 20 | 21 | function multiply(a, b) { 22 | return a * b; 23 | } 24 | 25 | function divide(a, b) { 26 | return a / b; 27 | } 28 | 29 | function factorial(a) { 30 | if (a == 0) return 1; 31 | let product = 1; 32 | for (let i = a; i > 0; i--) { 33 | product *= i; 34 | } 35 | return product; 36 | } 37 | 38 | function exponent(a, b) { 39 | return Math.pow(a, b); 40 | } 41 | 42 | function collectData(e) { 43 | warning.textContent = ''; 44 | let data = ''; 45 | if (e.key === undefined) { 46 | data = this.id; 47 | } else { 48 | data = e.key; 49 | } 50 | switch(data) { 51 | case '0': 52 | resetDisplayNumber(); 53 | if (hasPreviousFactorial() === false && exceedsDisplay() === false && hasDivision() === false) { 54 | displayNumber = displayNumber + '0'; 55 | } 56 | break; 57 | case '9': 58 | resetDisplayNumber(); 59 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 60 | displayNumber = displayNumber + '9'; 61 | } 62 | break; 63 | case '8': 64 | resetDisplayNumber(); 65 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 66 | displayNumber = displayNumber + '8'; 67 | } 68 | break; 69 | case '7': 70 | resetDisplayNumber(); 71 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 72 | displayNumber = displayNumber + '7'; 73 | } 74 | break; 75 | case '6': 76 | resetDisplayNumber(); 77 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 78 | displayNumber = displayNumber + '6'; 79 | } 80 | break; 81 | case '5': 82 | resetDisplayNumber(); 83 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 84 | displayNumber = displayNumber + '5'; 85 | } 86 | break; 87 | case '4': 88 | resetDisplayNumber(); 89 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 90 | displayNumber = displayNumber + '4'; 91 | } 92 | break; 93 | case '3': 94 | resetDisplayNumber(); 95 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 96 | displayNumber = displayNumber + '3'; 97 | } 98 | break; 99 | case '2': 100 | resetDisplayNumber(); 101 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 102 | displayNumber = displayNumber + '2'; 103 | } 104 | break; 105 | case '1': 106 | resetDisplayNumber(); 107 | if (hasPreviousFactorial() === false && exceedsDisplay() === false) { 108 | displayNumber = displayNumber + '1'; 109 | } 110 | break; 111 | case '.': 112 | case 'period': 113 | resetDisplayNumber(); 114 | if (displayNumber.length == 0 && hasPreviousFactorial() === false) { 115 | displayNumber = displayNumber + '0.'; 116 | } else if (hasPreviousFactorial() === false && hasPreviousPeriod() === false && hasExponent() === false && exceedsDisplay() === false) { 117 | displayNumber = displayNumber + '.'; 118 | } 119 | break; 120 | case 'Escape': 121 | case 'Delete': 122 | case 'clear': 123 | let clearConfirm = confirm('Are you sure you want to clear everything?'); 124 | if (clearConfirm) { 125 | displayNumber = ''; 126 | rawData = ''; 127 | } 128 | break; 129 | case 'ArrowUp': 130 | case 'ArrowDown': 131 | case 'positive-negative': 132 | if (exceedsDisplay() === false) { 133 | switchPositiveNegative(); 134 | } 135 | break; 136 | case '!': 137 | case 'factorial': 138 | if (hasPreviousNumber() === true && hasPreviousPeriod() === false && exceedsDisplay() === false && hasTwoDigitsMax() === true) { 139 | displayNumber = displayNumber + '!'; 140 | addDisplayToRaw(); 141 | displayNumber = ''; 142 | } 143 | break; 144 | case '^': 145 | case 'exponent': 146 | if (hasPreviousNumber() === true && hasPreviousPeriod() === false && exceedsDisplay() === false) { 147 | clearRawDataResult(); 148 | displayNumber = displayNumber + '^'; 149 | } 150 | break; 151 | case 'Backspace': 152 | resetDisplayNumber(); 153 | backspaceNumberOrOperator() 154 | break; 155 | case '+': 156 | case 'plus': 157 | if (hasPreviousOperator() === false) { 158 | addDisplayToRaw(); 159 | rawData = rawData + ' + '; 160 | displayNumber = ''; 161 | } else { 162 | warning.textContent = `You must have a number before choosing '+'` 163 | } 164 | break; 165 | case '-': 166 | case 'minus': 167 | if (hasPreviousOperator() === false) { 168 | addDisplayToRaw(); 169 | rawData = rawData + ' - '; 170 | displayNumber = ''; 171 | } else { 172 | warning.textContent = `You must have a number before choosing '-'` 173 | } 174 | break; 175 | case '*': 176 | case 'times': 177 | if (hasPreviousOperator() === false) { 178 | addDisplayToRaw(); 179 | rawData = rawData + ' * '; 180 | displayNumber = ''; 181 | } else { 182 | warning.textContent = `You must have a number before choosing '*'` 183 | } 184 | break; 185 | case '/': 186 | case 'divide': 187 | if (hasPreviousOperator() === false) { 188 | addDisplayToRaw(); 189 | rawData = rawData + ' / '; 190 | displayNumber = ''; 191 | } else { 192 | warning.textContent = `You must have a number before choosing '/'` 193 | } 194 | break; 195 | case '=': 196 | case 'Enter': 197 | case 'equals': 198 | addDisplayToRaw(); 199 | if (validEquation() === true) { 200 | copyRawDataToCalculate(); 201 | displayNumber = rawDataResult; 202 | } else { 203 | warning.textContent = `You must have a valid equation to solve. It can not end with '+ - * /'` 204 | } 205 | break; 206 | case 'Shift': 207 | // This is will allow shift to be used for '+ * ^ !' without triggering the default warning for keyboard shortcuts. 208 | break; 209 | default: 210 | warning.innerHTML = ` 211 |

Unusual Keyboard Shortcuts:

212 |
delete (mac) | backspace (pc)

213 |

AC escape (mac) | delete (pc)

214 |

+/- arrow up or down

215 | `; 216 | break; 217 | } 218 | display.textContent = displayNumber; 219 | displayRawData(); 220 | } 221 | 222 | function resetDisplayNumber() { 223 | if (rawDataResult != 0) { 224 | displayNumber = ''; 225 | rawDataResult = ''; 226 | } 227 | } 228 | 229 | // BOOLEAN CHECKS: 230 | 231 | // Limits the number of digits that can be entered at one time 232 | function exceedsDisplay() { 233 | if (displayNumber.length >= 12 || rawData.length >= 45) { 234 | warning.textContent = `The numbers have reached the limit of the display.` 235 | return true; 236 | } else { 237 | return false; 238 | } 239 | } 240 | 241 | // Check to see if user clicks two math operators back to back - exception: factorial (!) and period (.) 242 | function hasPreviousOperator() { 243 | if (displayNumber.length != 0 || (rawData.charAt(rawData.length - 1).match(/[\d!\.]/))) { 244 | return false; 245 | } else { 246 | return true; 247 | } 248 | } 249 | 250 | // Checks to see if user inputs number after factorial (for example: 3!4) 251 | function hasPreviousFactorial() { 252 | if (rawData.charAt(rawData.length - 1).match(/!/)) { 253 | warning.textContent = `Please enter a math operator after using a factorial.`; 254 | return true; 255 | } else { 256 | return false; 257 | } 258 | } 259 | 260 | // Factorials can increase too quickly, so I limited it to 2 digits 261 | function hasTwoDigitsMax() { 262 | if (displayNumber.length <= 2) { 263 | return true; 264 | } else { 265 | warning.textContent = `The max for a factorial is 2 digits on this calculator.`; 266 | return false; 267 | } 268 | } 269 | 270 | // Check to see if a user is trying to divide by 0, but still let user divide by 10 (for example: 32 / 0) 271 | function hasDivision() { 272 | if (rawData.charAt(rawData.length - 2).match(/\//) && displayNumber.length == 0) { 273 | warning.textContent = `This calculator will not divide by 0. I'm sure in your infinite wisdom you already know the answer to ${rawData} 0.`; 274 | return true; 275 | } else { 276 | return false; 277 | } 278 | } 279 | 280 | // Check to see if user clicked on period twice in the same number (for example: 3.14.159) 281 | function hasPreviousPeriod() { 282 | if (displayNumber.match(/\./)) { 283 | warning.textContent = `You can not have a decimal point in a exponent, factorial, or if there is already a decimal point.`; 284 | return true; 285 | } else { 286 | return false; 287 | } 288 | } 289 | 290 | // Check for an exponent in number, before adding a decimal point. 291 | function hasExponent() { 292 | if (displayNumber.match(/\^/)) { 293 | warning.textContent = `You can not use a decimal point in an exponent on this calculator`; 294 | return true; 295 | } else { 296 | return false; 297 | } 298 | } 299 | 300 | // Check to see if there is a number preceding for factorial and exponent 301 | function hasPreviousNumber() { 302 | if (displayNumber.charAt(displayNumber.length - 1).match(/\d/)) { 303 | return true; 304 | } else { 305 | warning.textContent = `You must enter a number before using a factorial or exponent`; 306 | return false; 307 | } 308 | } 309 | 310 | // CALCULATOR FUNCTIONALITY 311 | 312 | // Backspace 1 space in Display Number, or 1-3 spaces in Raw Data 313 | function backspaceNumberOrOperator() { 314 | // If there is a display number, delete from it first 315 | if (displayNumber.length >= 1) { 316 | let displayArray = displayNumber.split(''); 317 | displayArray.pop(); 318 | let displayString = displayArray.join(''); 319 | displayNumber = displayString; 320 | } else { 321 | let rawDataArray = rawData.split(''); 322 | // If the array has an empty string at the end (for example, from ' + ') 323 | if (rawDataArray.length >= 1 && rawDataArray[rawDataArray.length-1].match(/\s/)) { 324 | rawDataArray.pop(); 325 | rawDataArray.pop(); 326 | rawDataArray.pop(); 327 | } else { 328 | rawDataArray.pop(); 329 | } 330 | let rawDataString = rawDataArray.join(''); 331 | rawData = rawDataString; 332 | } 333 | } 334 | 335 | // Add or remove negative sign from display number 336 | function switchPositiveNegative() { 337 | // If there is not a display number, it will start with '-' 338 | if (displayNumber.length == 0) { 339 | displayNumber = '-'; 340 | } else { 341 | let displayArray = displayNumber.split(''); 342 | // If the display number is already negative, delete the '-' 343 | if (displayArray[0].match(/-/)) { 344 | displayArray.shift(); 345 | let displayString = displayArray.join(''); 346 | displayNumber = displayString; 347 | } else { 348 | // If the dislay number is positive, add a "-" to the begining of the array 349 | displayArray.unshift('-'); 350 | let displayString = displayArray.join(''); 351 | displayNumber = displayString; 352 | } 353 | } 354 | } 355 | 356 | // Add displayNumber to the end of rawData string 357 | function addDisplayToRaw() { 358 | if (rawDataResult.length == 0) { 359 | rawData = rawData + displayNumber; 360 | } else { 361 | rawData = displayNumber; 362 | rawDataResult = ''; 363 | } 364 | } 365 | 366 | // Must clear rawDataResult, to use exponents on the product on previous equation 367 | function clearRawDataResult() { 368 | if (rawDataResult.length != 0) { 369 | rawDataResult = ''; 370 | } 371 | } 372 | 373 | // Must valiate equation, so it does not end with +_*? - The last thing should be a digit or factorial 374 | function validEquation() { 375 | if (rawData.charAt(rawData.length - 1).match(/!|\d/)) { 376 | return true; 377 | } else { 378 | return false; 379 | } 380 | } 381 | 382 | // Make a copy of rawData to be able to display after calculateData 383 | function copyRawDataToCalculate() { 384 | let rawDataArray = rawData.split(' '); 385 | rawDataResult = rawDataArray.join(' '); 386 | calculateData(); 387 | } 388 | 389 | // Main function that processes the rawData to rawDataResult 390 | function calculateData() { 391 | if (rawDataResult.match(/\d+!/)) { 392 | solveFactorial(); 393 | } else if (rawDataResult.match(/\d+\^\d+/)) { 394 | solveExponent(); 395 | } else if (rawDataResult.match(/\*|\//)) { 396 | solveMultiplicationOrDivison(); 397 | } else if ((rawDataResult.match(/[\s][\+|-][\s]/))) { 398 | solveAdditionOrSubtraction(); 399 | } else { 400 | if (rawDataResult.length > 12) { 401 | // This formatting is not scientific 402 | formatRawDataResults(); 403 | return rawDataResult; 404 | } else { 405 | return rawDataResult; 406 | } 407 | } 408 | } 409 | 410 | function solveFactorial() { 411 | let factorialMatch = rawDataResult.match(/\d+!/)[0]; 412 | // Remove the '!' before running factorial function 413 | let factorialArray = factorialMatch.split(''); 414 | factorialArray.pop(); 415 | factorialNumber = factorialArray.join(''); 416 | let factorialResult = factorial(factorialNumber); 417 | // Replace the rawDataResult with the factorialResult 418 | let factoralRawData = /\d+!/[Symbol.replace](rawDataResult, factorialResult); 419 | rawDataResult = factoralRawData; 420 | calculateData(); 421 | } 422 | 423 | function solveExponent() { 424 | let exponentRegExp = /\d+\^\d+/; 425 | let exponentMatch = rawDataResult.match(exponentRegExp)[0]; 426 | // Find the whole and exponent to run exponent function 427 | let wholeNumber = exponentMatch.match(/^\d+/)[0]; 428 | let exponentNumber = exponentMatch.match(/\d+$/)[0]; 429 | let exponentResult = exponent(wholeNumber, exponentNumber); 430 | // replace rawDataResult with the exponentResult 431 | let exponentRawData = exponentRegExp[Symbol.replace](rawDataResult, exponentResult); 432 | rawDataResult = exponentRawData; 433 | calculateData(); 434 | } 435 | 436 | function solveMultiplicationOrDivison() { 437 | let multiplicationDivisionRegExp = /(\-?)[\d]+(\.?)[\d]*[\s][\*|\/][\s](\-?)[\d]+(\.?)[\d]*/; 438 | let multiplicationDivisionMatch = rawDataResult.match(multiplicationDivisionRegExp)[0]; 439 | let isMultiplicationOrDivision = multiplicationDivisionMatch.match(/\*|\//)[0]; 440 | // Find the two numbers to run multiplication or division function 441 | let numberRegExp = /(\-?)[\d]+(\.?)[\d]*/g; 442 | let firstNumber = multiplicationDivisionMatch.match(numberRegExp)[0]; 443 | let secondNumber = multiplicationDivisionMatch.match(numberRegExp)[1]; 444 | if (isMultiplicationOrDivision == '*') { 445 | let multiplicationResult = multiply(firstNumber, secondNumber); 446 | // Replace rawDataResult with multiplicationResult 447 | let multiplicationRawData = multiplicationDivisionRegExp[Symbol.replace](rawDataResult, multiplicationResult); 448 | rawDataResult = multiplicationRawData; 449 | } else { 450 | let divisionResult = divide(firstNumber, secondNumber); 451 | // Replace rawDataResult with divisionResult 452 | let divisionRawData = multiplicationDivisionRegExp[Symbol.replace](rawDataResult, divisionResult); 453 | rawDataResult = divisionRawData; 454 | } 455 | calculateData(); 456 | } 457 | 458 | function solveAdditionOrSubtraction() { 459 | // Need to go from left to right finding all of the + or - symbols 460 | const additionSubtractionRegExp = /(\-?)[\d]+(\.?)[\d]*[\s][\+|-][\s](\-?)[\d]+(\.?)[\d]*/; 461 | let additionSubtractionMatch = rawDataResult.match(additionSubtractionRegExp)[0]; 462 | let isAdditionOrSubtraction = additionSubtractionMatch.match(/[\s][\+|-][\s]/)[0]; 463 | let numberRegExp = /(\-?)[\d]+(\.?)[\d]*/g; 464 | let firstNumber = Number(additionSubtractionMatch.match(numberRegExp)[0]); 465 | let secondNumber = Number(additionSubtractionMatch.match(numberRegExp)[1]); 466 | if (isAdditionOrSubtraction == ' + ') { 467 | let additionResult = add(firstNumber, secondNumber); 468 | let additionRawData = additionSubtractionRegExp[Symbol.replace](rawDataResult, additionResult); 469 | rawDataResult = additionRawData; 470 | } else { 471 | let subtractionResult = subtract(firstNumber, secondNumber); 472 | let subtractionsRawData = additionSubtractionRegExp[Symbol.replace](rawDataResult, subtractionResult); 473 | rawDataResult = subtractionsRawData; 474 | } 475 | calculateData() 476 | } 477 | 478 | // Re-sets the rawData after the equal sign has been used 479 | function displayRawData() { 480 | if (rawDataResult.length == 0) { 481 | rawDisplay.textContent = rawData; 482 | } else { 483 | rawDisplay.textContent = rawData; 484 | rawData = ''; 485 | } 486 | } 487 | 488 | // This is not a REAL scientific notation calculation - This is simply gives an illusion that it is to keep calculator within 12 digit limit 489 | function formatRawDataResults() { 490 | removeDigits = (rawDataResult.length - 10); 491 | formattedRawDataArray = rawDataResult.split(''); 492 | let notationRegExp = /e\+*\d+/; 493 | let decimalRegExp = /\./; 494 | // Find if there is scientific notation & if so, get length & remove 'n' 495 | if (rawDataResult.match(notationRegExp)) { 496 | rawDataMatch = rawDataResult.match(notationRegExp)[0]; 497 | oldNotation = rawDataMatch.length - 1; 498 | rawDataResult = /e\+*/[Symbol.replace](rawDataResult, 0); 499 | addNotation(oldNotation); 500 | // If the number is less then 1 million & has a decimal point, only remove digits. 501 | } else if (rawDataResult < 1000000000 && rawDataResult.match(decimalRegExp)) { 502 | for (i = 1; i <= removeDigits - 2; i++) { 503 | formattedRawDataArray.pop(); 504 | } 505 | let formattedRawData = formattedRawDataArray.join(''); 506 | rawDataResult = formattedRawData; 507 | 508 | } else { 509 | addNotation(0); 510 | } 511 | warning.textContent = `The result has been formatted to fit in the display area`; 512 | } 513 | 514 | // Need to either remove enough places for single or double digits in scientific notation 515 | function addNotation(oldNotation) { 516 | if ((removeDigits + oldNotation) >= 10) { 517 | for (i = 0; i <= removeDigits; i++) { 518 | formattedRawDataArray.pop(); 519 | } 520 | } else { 521 | for (i = 1; i <= removeDigits; i++) { 522 | formattedRawDataArray.pop(); 523 | } 524 | } 525 | let formattedRawData = formattedRawDataArray.join('') + `e${removeDigits + oldNotation}`; 526 | rawDataResult = formattedRawData; 527 | } 528 | 529 | // Footer Hover 530 | 531 | function grayIcon() { 532 | footerIcon.src = "img/github-gray.svg"; 533 | } 534 | 535 | function whiteIcon() { 536 | footerIcon.src = "img/github-white.svg"; 537 | } 538 | 539 | calcButtons.forEach(calcButton => calcButton.addEventListener('click', collectData)) 540 | window.addEventListener('keydown', collectData); 541 | footerIcon.addEventListener('mouseenter', grayIcon); 542 | footerIcon.addEventListener('mouseleave', whiteIcon); 543 | --------------------------------------------------------------------------------