Here you can get Code for Simple Calculator Using HTML, CSS, and JavaScript .The best way to learn JavaScript is to build projects. If you want to become a good web developer, you need to start creating projects as soon as possible. You can start by building beginner-level projects like a simple calculator, digital clock, or stopwatch.
You can make a simple calculator using just core web technologies: HTML, CSS, and JavaScript. This calculator can perform basic mathematical operations like addition, subtraction, multiplication, and division.
Here is a Code for Simple Calculator Using HTML, CSS, and JavaScript
Note: It’s important to keep in mind that this is a very basic calculator and should not be used for complex calculations or critical financial calculations.
Also read: How to Fix Connected to Wi-Fi but No Internet Error
Code for Simple Calculator:
" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button">
/span> html>
Simple Calculator
body {
font-family: Arial, sans-serif;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.calculator {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(5, 1fr);
gap: 10px;
padding: 20px;
background-color: #f2f2f2;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}
button {
border: none;
outline: none;
background-color: #e6e6e6;
font-size: 24px;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #d9d9d9;
}
button:active {
background-color: #c2c2c2;
}
.output {
grid-column: 1 / -1;
text-align: right;
font-size: 36px;
padding: 10px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
}
class="container">
class="calculator">
class="output" id="output">0
let output = document.getElementById("output");
function appendToOutput(value) {
if (output.innerHTML === "0") {
output.innerHTML = "";
}
output.innerHTML += value;
}
function clearOutput() {
output.innerHTML = "0";
}
function backspace() {
output.innerHTML = output.innerHTML.slice(0, -1);
if (output.innerHTML === "") {
output.innerHTML = "0";
}
}
function calculate() {
output.innerHTML = eval(output.innerHTML);
}
/
Code for Simple Calculator output
After you install the code here is the output color is depends on your Theme This code defines a runCode()
function that takes the user’s input for HTML, CSS, and JavaScript code, combines them into a single HTML document, and displays the output in an iframe. The HTML code defines a simple form with textareas for the code input and a button to trigger the runCode()
function. When the button is clicked, the runCode()
function is called with the input values, and the output is displayed in an iframe. The CSS styles are used to lay out the form and the output iframe. also link this page to your website