Calculator
How do I make an calculator?
Calculator for Free Code Camp using JQuery. What is a calculator? How do you make a calculator? This script and codes were developed by Adam on 28 November 2022, Monday.
Calculator - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Calculator </title> <link href="https://fonts.googleapis.com/css?family=Archivo+Black|Orbitron" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div> <div class="calc"> <div class="row"> <div class="title">KASIO</div> <div class="solar"> <div></div> <div></div> <div></div> <div></div> </div> <div class="info">Calculator</div> </div> <div class="wrap"> <div class="back-numbers">.00000000</div> <div class="back-numbers2">000000000000000000</div> <div class="screen display">0</div> <div class="screen calc-display"></div> </div> <div class="row"> <button data-key="ac" class="utility">AC</button> <button data-key="c" class="utility">C</button> <button data-key="ce" class="ce">CE</button> <button data-key="%" class="operator">%</button> </div> <div class="row"> <button data-key="7">7</button> <button data-key="8">8</button> <button data-key="9">9</button> <button data-key="/" class="operator">÷</button> </div> <div class="row"> <button data-key="4">4</button> <button data-key="5">5</button> <button data-key="6">6</button> <button data-key="*" class="operator">X</button> </div> <div class="row"> <button data-key="1">1</button> <button data-key="2">2</button> <button data-key="3">3</button> <button data-key="-" class="operator">-</button> </div> <div class="row"> <button data-key="0">0</button> <button data-key=".">.</button> <button data-key="=" class="operator">=</button> <button data-key="+" class="operator">+</button> </div> </div> <div class="flip-button">Flip</div>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Calculator - Script Codes CSS Codes
html { font-size: 20px;
}
body { display: flex; justify-content: center; margin-top: 60px; background-color: #333333; color: white; font-family: 'Archivo Black', sans-serif;
}
.calc { width: 300px; height: 450px; display: flex; flex-direction: column; justify-content: space-around; align-items: center; background: #324159; background: linear-gradient(to bottom right, #324159, #253041); border-radius: 25px; box-shadow: 5px 5px 5px #111111;
}
.row { display: flex; justify-content: space-around; align-items: center; width: 260px; height: 60px;
}
.title { padding-right: 10px; font-size: 1rem; text-shadow: 2px 2px 3px #111111;
}
.info { padding-left: 10px; font-size: 0.8rem; text-shadow: 2px 2px 3px #111111;
}
.solar { display: flex; width: 80px; height: 20px; background-color: #001a00; border-radius: 5px; border: 2px solid black; box-shadow: 2px 2px 0px #253041;
}
.solar > div { width: 20px; height: 20px; border-left: 2px solid black;
}
.solar > div:first-child { border-left: none;
}
.wrap { position: relative; font-family: 'Orbitron', sans-serif; font-size: 30px;
}
.back-numbers { position: absolute; color: rgba(0, 0, 0, 0.05); top: 6px; left: 32px;
}
.back-numbers2 { position: absolute; color: rgba(0, 0, 0, 0.05); top: 50px; left: 17px; font-size: 0.8rem;
}
.screen { display: flex; justify-content: flex-end; text-align: center; height: 30px; width: 250px; padding: 2px 3px; background-color: #bbccbc; color: black; border: 5px solid #253041; border-radius: 8px;
}
.calc-display { display: flex; justify-content: flex-end; align-items: flex-end; margin-top: -7px; margin-bottom: 15px; font-size: 0.8rem; border-top: none; border-radius: 0 0 10px 10px;
}
button { height: 46px; width: 56px; color: white; background-color: #AAAAAA; font-weight: bold; font-size: 1.4rem; font-family: 'gotham rounded', sans-serif; text-shadow: 1px 1px 3px #111111; border-width: 2px 3px 3px 2px; border-color: #999999; border-radius: 10px 10px 20px 20px; cursor: pointer;
}
.utility { background-color: #ed4964; border-color: #a50d30; font-size: 1.3rem;
}
.operator { background-color: #222222; border-color: #444444;
}
.ce { background-color: #68cc9b; border-color: #39ac75; font-size: 1.3rem;
}
.flip { transform: rotate(180deg);
}
.flip-button { width: 100px; margin: 15px 0 0 100px; background: red; text-shadow: 1px 1px 3px #111111; border-width: 2px 3px 3px 2px; border-color: #999999; border-radius: 10px 10px 10px 10px; font-weight: bold; font-size: 1.4rem; font-family: 'gotham rounded', sans-serif; text-align: center; cursor: pointer;
}
Calculator - Script Codes JS Codes
/* JQuery calculator with flip button to write school kid messages*/
$(document).ready(function() { var answer = 0; //Store expression var exp = ""; //Operator array and function to check if user input is an operator var operators = ["+", "-", "*", "/", "%", "="]; function opCheck(input) { for (var i = 0; i < operators.length; i++) { if (input === operators[i]) { return true; } } } //Power On/Off Function var powerOn = false; function power() { if (powerOn === true) { $('.display').text(""); $('.calc-display').text(""); $('button').attr("disabled", true); $("button[data-key='ac']").removeAttr("disabled"); exp = ""; powerOn = false; } else if (powerOn === false) { $('.display').text("0"); $('.calc-display').text(""); $('button').removeAttr("disabled"); exp = "" powerOn = true; } } //Clear function function clear() { $('.display').text("0"); $('.calc-display').text(""); exp = ""; } // Check if input is valid based on previous selection function inputCheck() { var input = $(this).data("key"); //Check power if (input === "ac") { return; } //Check clear if (input === "c") { clear(); return; } //Check delete if (input === "ce") { exp = exp.substring(0, exp.length - 1); $('.calc-display').text(exp); $('.display').text("0"); return; } //Check expression length if (exp.length > 17) { exp = exp.substring(0, exp.length - 1); } //Prevent consecutive operators if (opCheck(input)) { if (opCheck(exp[exp.length - 1])) { exp = exp.substring(0, exp.length - 1) } } //Add input to expression exp += input; //Check if first entry is decimal and prevent multiple decimal points if (exp[0] === ".") { exp = "0."; } if (input === ".") { if (exp.substring(0, exp.length - 1).includes(".")) { exp = exp.substring(0, exp.length - 1); } } //enable operators after a number if (opCheck(exp[0])) { clear(); } //Check and perform percentage calculation if (input === "%") { exp = exp.substring(0, exp.length - 1) answer = eval(exp) / 100; $('.display').text(answer); $('.calc-display').text(exp); exp = ""; return; } //Update displays $('.display').text(exp[exp.length - 1]); $('.calc-display').text(exp); //Return answer and reduce length if needed if (input === "=") { exp = exp.substring(0, exp.length - 1) answer = eval(exp); if (answer.toString().length > 10) { answer = answer.toString().substring(0, 10) } $('.display').text(answer); exp = ""; } } function flip() { $(".calc").toggleClass('flip'); } //Event handlers $(".flip-button").click(flip); $("button").click(inputCheck); $("button[data-key='ac']").click(power);
});

Developer | Adam |
Username | rzencoder |
Uploaded | November 28, 2022 |
Rating | 3 |
Size | 4,572 Kb |
Views | 6,069 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Whack-a-Mole and Simon Game | 10,604 Kb |
Random Movie Quote Generator | 3,861 Kb |
React Betting App | 6,005 Kb |
Countdown Anagram Game | 7,625 Kb |
React Leaderboard | 4,333 Kb |
React Game of Life | 7,264 Kb |
The Crystal Maze | 16,117 Kb |
Scatterplot Graph D3 | 5,762 Kb |
Map Data Across the Globe | 3,900 Kb |
Playable Piano Keyboard with Demos | 10,019 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Calendar | Miroot | 2,033 Kb |
Weird glowy CSS3 game | Toneworm | 3,684 Kb |
Hoi hoi | JohnTheCat | 7,248 Kb |
Scroll Arrow | Robooneus | 4,437 Kb |
Cut and Paste Roll Link | BottomlineInteractive | 2,546 Kb |
Horizontal scroll fixed element | HerrSerker | 0 Kb |
Pericles mi loro... | Judag | 4,125 Kb |
Factorial | KeithleySLHS | 1,158 Kb |
Eunice A | Ejbronze | 2,203 Kb |
Text Looping Transition | Agelber | 5,619 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!