Calculator
How do I make an calculator?
What is a calculator? How do you make a calculator? This script and codes were developed by Sky on 29 January 2023, Sunday.
Calculator - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Calculator</title> <link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Roboto'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="calculator"> <div class="top-bar"> <span class="float-left">☰</span> <span class="logo">SkyCalc™</span> <span class="float-right">🔋 🔌</span> </div> <div class="screen"> <div class="equation"></div> <div class="total"></div> </div> <div class="buttons text-left"> <span id="clear" class="button clear"> <div class="teardrop"> <span class="teardrop-icon-text">x</span> </div> </span> <span id="plusminus" class="button">±</span> <span id="divide" class="button operator">/</span> <span id="multiply" class="button operator">x</span> <span id="7" class="button number">7</span> <span id="8" class="button number">8</span> <span id="9" class="button number">9</span> <span id="subtract" class="button operator">-</span> <span id="4" class="button number">4</span> <span id="5" class="button number">5</span> <span id="6" class="button number">6</span> <span id="add" class="button operator">+</span> <span id="1" class="button number">1</span> <span id="2" class="button number">2</span> <span id="3" class="button number">3</span> <span id="equals" class="button equals">=</span> <span id="0" class="button zero number">0</span> <span id="decimal" class="button decimal number">.</span> </div>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Calculator - Script Codes CSS Codes
@font-face { font-family: 'calculator'; src: url('https://SkyC0der.github.io/fonts/calculator.woff') format('woff'), url('https://SkyC0der.github.io/fonts/calculator.svg#calculator') format('svg'), url('https://SkyC0der.github.io/fonts/calculator.eot'), url('https://SkyC0der.github.io/fonts/calculator.eot?#iefix') format('embedded-opentype'); font-weight: normal; font-style: normal;
}
body { background-image: -webkit-linear-gradient(left, rgb(184, 184, 184), rgb(222,222,222)); background-image: linear-gradient(to right, rgb(184, 184, 184), rgb(222,222,222)); color: #eee; font-family: Roboto; margin: 5vh auto 0 auto; min-width: 268px;
}
.calculator { background-color: #222; box-shadow: 0 8px 37px 0 rgba(0, 0, 0, .8), 0 6px 60px 0 rgba(0, 0, 0, .8); display: block; width: 268px; margin: 0 auto; text-align: center; max-height: 485px;
}
.top-bar { font-size: 14px; height: 25px; background-color: black; line-height: 25px; padding-left: 7px; padding-right: 7px;
}
.logo { position: absolute; left: 0; right: 0; min-width: 268px;
}
.screen { height: 130px; background-color: #010101; word-break: break-all; padding: 10px 10px 0 32px; text-align: right; font-family: 'calculator', monospace;
}
.equation { font-size: 24px; padding: 3px;
}
.equation:focus { background-color: #101010; outline: none;
}
.total { font-size: 36px; margin-top: 25px; white-space: nowrap;
}
.buttons { font-size: 0; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; cursor: pointer;
}
.button:hover { background: rgba(34,34,34,0.95);
}
.button:active { background-color: rgba(255,255,255,0.05);
}
.button { background: #222; background: -webkit-linear-gradient(left, rgb(52,52,52), rgb(34,34,34)); background: linear-gradient(to right, rgb(52,52,52), rgb(34,34,34)); border: 1px solid #121212; display: inline-block; font-size: 16px; font-weight: bold; height: 40px; margin: 0; padding-top: 22px; text-align: center; vertical-align: middle; width: 65px;
}
.teardrop { width: 1.5em; height: 1.5em; border-radius: 80% 0 55% 50% / 55% 0 80% 50%; background: #eee; margin-left: 20px; margin-top: -3px; -webkit-transform: rotateZ(225deg); transform: rotateZ(225deg);
}
/* need to figure out text - doesn't display consistently across browsers */
.teardrop-icon-text { color: #222; font-weight: normal; -webkit-transform: rotateZ(-225deg); transform: rotateZ(-225deg); position: absolute; top: 3px; right: 7px;
}
.clear-icon { background-color: #eee; border-radius: 50%; min-width: 30px; min-height: 30px; line-height: 30px; display: inline-block; color: #222; margin-top: -15px; position: relative; z-index: 0;
}
.equals { background: -webkit-linear-gradient(left, rgb(255,250,0), rgb(255,195,13), rgb(255,195,13), rgb(255,250,0)); background: linear-gradient(to right, rgb(255,250,0), rgb(255,195,13), rgb(255,195,13), rgb(255,250,0)); border-right: 1px solid #222; border-bottom: 1px solid #222; color: #222; height: 36px; padding-top: 90px; vertical-align: top; position: absolute;
}
.equals:hover { background-color: rgb(255,210,0);
}
.equals:active { background-color: rgb(255,230,0);
}
.zero { width: 132px;
}
.float-left { float: left;
}
.float-right { float: right;
}
.text-left { text-align: left;
}
Calculator - Script Codes JS Codes
"use strict";
$(".clear").on("click", function (e) { return $(".equation, .total").empty();
});
$("#plusminus").on("click", function () { return updateEquationText("x-1");
});
$(".number, .operator").on("click", validateInput);
// eval() is fine here because we control the input
$("#equals").on("click", function () { return $(".total").text(eval($(".equation").text().replace(/x/g, "*")));
});
// series of tests for input validation before updating the display
function validateInput(e) { var $equation = $(".equation"), equationText = $equation.text(), lastNumberEntered = equationText.split(/\+|-|\/|x/).slice(-1).toString(), entry = $(e.target).text(); // only one operator in a row - need to make it replace the last one entered... if ($(e.target).hasClass("operator") && /^\s*$|(\+|-|\/|x|\*)$/.test(equationText)) return; // only one decimal in a row if ($(e.target).hasClass("decimal") && lastNumberEntered.includes(".")) return; // add a 0 before the decimal if it's at the start of a number $(e.target).hasClass("decimal") && /\D$|^\s*$/.test(equationText) ? updateEquationText("0" + entry) : updateEquationText(entry);
}
function updateEquationText(text) { $(".equation").text($(".equation").text() + text);
}
Developer | Sky |
Username | skycoder |
Uploaded | January 29, 2023 |
Rating | 3 |
Size | 4,133 Kb |
Views | 2,024 |
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 |
Use the Twitch.tv JSON API | 2,862 Kb |
FCC Leaderboard - vanilla JS | 2,546 Kb |
Feather Icons | 2,918 Kb |
Ionicons | 6,688 Kb |
Media Queries | 2,045 Kb |
Show the Local Weather - and a local background image | 8,205 Kb |
Random Quote Machine | 2,259 Kb |
Portfolio - Work In Progress | 4,572 Kb |
Vanilla JS Forismatic Example | 2,284 Kb |
Colors and Sounds | 4,204 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 |
Button fills | Zubfatal | 5,205 Kb |
Tail rose iris lined | Kbrtrm | 1,846 Kb |
Break Out | AzazelN28 | 12,431 Kb |
OnScreenAction | Ozgursagiroglu | 2,647 Kb |
HTML5 Breakout | Jaysalvat | 4,873 Kb |
Custom checkbox example | Capelo | 3,495 Kb |
Mesmerizing octopus | Jllodra | 3,549 Kb |
Responsive Section hover effect to show content | Berdejitendra | 2,540 Kb |
Sample Profile Screen | OurDailyBread | 5,375 Kb |
Headroom.js demo | WickyNilliams | 3,982 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!