Calculator In JavaScript Source Code
The Calculator In JavaScript Source Code is developed using JavaScript, CSS, bootstrap, and HTML. This Calculator In JavaScript Using Function as that of a real-life simple calculator. The Calculator In JavaScript is for solving the mathematical calculations of numbers. You can see the basic features of the calculator in this project.
A Calculator JavaScript Features; the user can add, subtract, divide, multiply, even check the remainder of any two numbers. You can just click the numbers you want to involve in calculations and click the button with “=” sign for the result.
This Calculator In JavaScript and HTML project with source code also includes a downloadable Calculator In JavaScript Source Code for free, just find the downloadable source code below and click to start downloading.
Watch the video here to see the full running Calculator In JavScript Project With Source Code.
I have here a suggested list of Best JavaScript Projects with Source Code Free to download and I’m sure this can help you to improve your skills in JavaScript programming and web development as a whole.
To start creating a Calculator In JavaScript Source Code, makes sure that you have any platform in creating a JavaScript, CSS, bootstrap, and HTML installed in your computer, in my case I will use Sublime Text.
Steps on how to create a Calculator In JavaScript Source Code
Calculator In JavaScript Source Code
- Step 1: Open Sublime Text.
First after installing sublime text IDE, click “open” to start.
- Step 2: Create a HTML file.
Second click “file” and select “save as” and named it “index.html“
- Step 3: Create a CSS file.
Third click “file” and select “save as” and named it “style.css“
- Step 4: Create a JavaScript file.
Fourth click “file” and select “save as” and named it “app.js“
- Step 5: The actual code.
You are free to copy the code given below and paste to your different file created.
The Code Given Below Is For The Index module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<html> <head> <link rel="stylesheet" type="text/css" href="styles.css"> <link href="https://fonts.googleapis.com/css?family=Open+Sans:600,700" rel="stylesheet"> <title>A simple calculator</title> </head> <body> <div id="container"> <div id="calculator"> <div id="result"> <div id="history"> <p id="history-value"></p> </div> <div id="output"> <p id="output-values"></p> </div> </div> <div id="keyboard"> <button class="operator" id="clear">C</button> <button class="operator" id="backspace">CE</button> <button class="operator" id="%">%</button> <button class="operator" id="/">÷</button> <button class="number" id="7">7</button> <button class="number" id="8">8</button> <button class="number" id="9">9</button> <button class="operator" id="*">&times;</button> <button class="number" id="4">4</button> <button class="number" id="5">5</button> <button class="number" id="6">6</button> <button class="operator" id="-">-</button> <button class="number" id="1">1</button> <button class="number" id="2">2</button> <button class="number" id="3">3</button> <button class="operator" id="+">+</button> <button class="empty" id="empty"></button> <button class="number" id="0">0</button> <button class="empty" id="empty"></button> <button class="operator" id="=">=</button> </div> </div> </div> <script src="script.js"></script> </body> </html> |
In this module which is the index of the system project.
The Code Given Below Is For The Module Script.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
function getHistory(){ return document.getElementById("history-value").innerText; } function printHistory(num){ document.getElementById("history-value").innerText=num; } function getOutput(){ return document.getElementById("output-values").innerText; } function printOutput(num){ if(num==""){ document.getElementById("output-values").innerText=num; } else{ document.getElementById("output-values").innerText=getFormattedNumber(num); } } function getFormattedNumber(num){ if(num=="-"){ return ""; } var n=Number(num); var value= n.toLocaleString("en"); return value; } function reverseNumberFormat(num){ return Number(num.replace(/,/g, '')); } var operator = document.getElementsByClassName("operator"); for( var i=0;i<operator.length;i++){ operator[i].addEventListener('click',function(){ if(this.id=="clear"){ printHistory(""); printOutput(""); } else if(this.id=="backspace"){ var output=reverseNumberFormat(getOutput()).toString(); if(output){//if output has a value output= output.substr(0,output.length-1); printOutput(output); } } else{ var output = getOutput(); var history = getHistory(); if(output==""&&history!=""){ if(isNaN(history[history.length-1])){ history=history.substr(0,history.length-1); } } if(output!="" || history!=""){ output= output==""? output:reverseNumberFormat(output); history=history+output; if(this.id=="="){ var result= eval(history); printOutput(result); printHistory(""); } else{ history=history+this.id; printHistory(history); printOutput(""); } } } }); } var number = document.getElementsByClassName("number"); for(var i=0;i<number.length;i++){ number[i].addEventListener('click',function(){ var output=reverseNumberFormat(getOutput()); if(output!=NaN){ output=output+this.id; printOutput(output); } }); } |
In this module which is the javaScript file of the system.
The Code Given Below Is For The Module Style.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
body{ font-family: 'Open Sans',sans-serif; background-color:black; } #container{ width: 1000px; height: 550px; background-image:linear-gradient(rgba(0,0,0,0.6),rgba(0,0,0,0.6)), url(Sugar-Excipients.jpg); margin: 20px auto; } #calculator{ width: 320px; height: 520px; background-color: #eaedef; margin: 0 auto; top: 20px; position: relative; border-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0.2), 0 6px 20px 0 rgba(0,0,0,0.19); } #result{ height: 120px; } #history{ text-align: right; height: 20px; margin: 0 20px; padding-top: 20px; font-size: 15px; color: #919191; } #output{ text-align: right; height: 60px; margin: 10px 20px; font-size: 30px; } #keyboard{ height: 400px; } .operator, .number, .empty{ width: 50px; height: 50px; margin: 15px; float: left; border-radius: 50%; border-width: 0; font-size: 15px; font-weight: bold; } .number, .empty{ background-color: #eaedef; } .operator{ background-color:lightgrey; } .number, .operator{ cursor: pointer; } .number:active, .operator:active{ font-size: 13px; } .number:focus, .operator:focus, .empty:focus{ outline: 0; } button:nth-child(4){ font-size: 20px; background-color: #20b2aa; } button:nth-child(8){ font-size: 20px; background-color: #ffa500; } button:nth-child(12){ font-size: 20px; background-color: #f08080; } button:nth-child(16){ font-size: 20px; background-color: #7d93e0; } button:nth-child(20){ font-size: 20px; background-color: #9477af; } |
In this module which is the css file of the system.
Run Quick Virus Scan for secure Download
Run Quick Scan for secure DownloadDownloadable Source Code
Summary
This JavaScript Project With Source Code is simply in HTML, CSS, and JavaScript. Taking about the features of this system, the user can add, subtract, divide, multiply, even check the remainder of any two numbers. You can just click the numbers you want to involve in calculations and click the button with “=” sign for the result. This project includes a lot of javascript for making the functioning of the project.
Related Articles
Inquiries
If you have any questions or suggestions about Calculator In JavaScript Source Code , please feel free to leave a comment below.