├── README.md ├── LICENSE ├── index.html ├── calculator.js └── style.css /README.md: -------------------------------------------------------------------------------- 1 | # simple_calculator 2 | Calculator in JS 3 | Demo: https://surajaswal-dev.github.io/js_calculator/ 4 | ![Screenshot (274)](https://user-images.githubusercontent.com/87890258/150632386-14d4fc11-8214-4c6f-8b12-c16dd16968fb.png) 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Suraj Aswal 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 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Calculator 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 | 16 | 17 |
18 |
19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |

Your calculation will be displayed here

29 |
30 |
31 |
32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /calculator.js: -------------------------------------------------------------------------------- 1 | //operands 2 | const firstNum=document.querySelector("#first_num"); 3 | const secondNum=document.querySelector("#second_num"); 4 | const showOutput=document.querySelector("#show-output"); 5 | 6 | // operations 7 | const add=document.querySelector("#addition"); 8 | const minus=document.querySelector("#subtraction"); 9 | const multiply=document.querySelector("#multiplication"); 10 | const divide=document.querySelector("#division"); 11 | const clear=document.querySelector("#clear"); 12 | 13 | // addition 14 | function addition(x,y){ 15 | const firstNumber=Number(x); 16 | const secondNumber=Number(y); 17 | 18 | const addOut=`Addition of ${firstNumber} & ${secondNumber} is ${firstNumber + secondNumber}`; 19 | return showOutput.textContent=addOut; 20 | } 21 | 22 | add.onclick=function(){ 23 | addition(firstNum.value,secondNum.value); 24 | } 25 | 26 | // subtraction 27 | function subtraction(x,y){ 28 | const firstNumber=Number(x); 29 | const secondNumber=Number(y); 30 | 31 | const minusOut=`Subtraction of ${firstNumber} & ${secondNumber} is ${firstNumber - secondNumber}`; 32 | return showOutput.textContent=minusOut; 33 | } 34 | 35 | minus.onclick=function(){ 36 | subtraction(firstNum.value,secondNum.value); 37 | } 38 | 39 | // multipication 40 | function multipication(x,y){ 41 | const firstNumber=Number(x); 42 | const secondNumber=Number(y); 43 | 44 | const multiplyOut=`Multipication of ${firstNumber} & ${secondNumber} is ${firstNumber * secondNumber}`; 45 | return showOutput.textContent=multiplyOut; 46 | } 47 | 48 | multiply.onclick=function(){ 49 | multipication(firstNum.value,secondNum.value); 50 | } 51 | 52 | // Division 53 | function division(x,y){ 54 | const firstNumber=Number(x); 55 | const secondNumber=Number(y); 56 | 57 | const divideOut=`Division of ${firstNumber} & ${secondNumber} is ${firstNumber / secondNumber}`; 58 | return showOutput.textContent=divideOut; 59 | } 60 | 61 | divide.onclick=function(){ 62 | division(firstNum.value,secondNum.value); 63 | } 64 | 65 | // clear 66 | function clearEvr(){ 67 | firstNum.value=""; 68 | secondNum.value=""; 69 | showOutput.textContent="Your calculation will be displayed here"; 70 | } 71 | 72 | clear.onclick=function(){ 73 | clearEvr(); 74 | } -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | *{ 2 | margin:0; 3 | padding: 0; 4 | font-family: Arial, Helvetica, sans-serif; 5 | box-sizing: border-box; 6 | } 7 | .main-wrap{ 8 | height:100vh; 9 | width:100%; 10 | background-color: burlywood; 11 | display: flex; 12 | align-items: center; 13 | justify-content: center; 14 | } 15 | .cal-box{ 16 | height:300px; 17 | width:550px; 18 | background-color: #fff; 19 | padding: 10px; 20 | } 21 | .cal-display{ 22 | height:60px; 23 | width:100%; 24 | background-color: rgb(248, 248, 248); 25 | padding:5px 10px; 26 | } 27 | .cal-display input{ 28 | height: 50px; 29 | padding:0px 4px; 30 | border: none; 31 | background-color: #fff; 32 | outline: none; 33 | font-size: 24px; 34 | border: 1px solid rgb(223, 223, 223); 35 | } 36 | .cal-display .num-input{ 37 | width:48%; 38 | } 39 | .cal-display .main-operand{ 40 | width:15%; 41 | } 42 | .cal-display input::placeholder{ 43 | color: rgb(226, 225, 225); 44 | } 45 | .cal-button{ 46 | width:100%; 47 | margin: 14px 0px; 48 | display: flex; 49 | justify-content: center; 50 | align-items: center; 51 | } 52 | .cal-button .cal-number{ 53 | width:50%; 54 | height: 200px; 55 | display: flex; 56 | flex-flow: wrap; 57 | justify-content: space-around; 58 | /* border: 1px solid rgb(231, 231, 231); */ 59 | } 60 | .cal-number .num-pad, .cal-operation .num-pad{ 61 | height:60px; 62 | width:60px; 63 | border: none; 64 | outline:none; 65 | border-radius: 4px; 66 | margin: 6px; 67 | color: #fff; 68 | font-weight: 500; 69 | font-size: 20px; 70 | cursor: pointer; 71 | } 72 | .numpad-bg{ 73 | background-color: rgb(78, 144, 199); 74 | } 75 | .cal-number .numpad-bg:hover{ 76 | background-color: rgb(20, 129, 180); 77 | } 78 | .cal-number .operands-bg{ 79 | background-color: rgb(54, 179, 116); 80 | } 81 | .cal-number .operands-bg:hover{ 82 | background-color: rgb(35, 143, 89); 83 | } 84 | .clear{ 85 | background-color: rgb(230, 14, 14); 86 | width:140px !important; 87 | } 88 | .cal-button .cal-output{ 89 | width: 50%; 90 | height:200px; 91 | background-color: #fff; 92 | padding: 10px; 93 | background-color: aliceblue; 94 | } 95 | #show-output{ 96 | padding: 5px; 97 | color:rgb(143, 142, 142); 98 | } --------------------------------------------------------------------------------