Simple Calculator_Freecodecamp

Developer
Size
2,283 Kb
Views
8,096

How do I make an simple calculator_freecodecamp?

What is a simple calculator_freecodecamp? How do you make a simple calculator_freecodecamp? This script and codes were developed by Shikun Ke on 28 November 2022, Monday.

Simple Calculator_Freecodecamp Previews

Simple Calculator_Freecodecamp - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Simple Calculator_Freecodecamp</title> <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <body>
<div class="container">
<div class="calculator text-center"> <p id="demo" class="display"></p> <div class="control-penal"> <div class="row"> <button text="AC" class="btn btn-danger" onclick="clear()">AC</button> <button class="btn btn-danger" onclick="clear()">CE</button> <button class="btn btn-primary" value="%" onclick="getOperation(this.value)">%</button> <button class="btn btn-primary" value="/" onclick="getOperation(this.value)">÷</button> </div> <div class="row"> <button class="btn" value="7"onclick="getNumber(this.value)">7</button> <button class="btn" value="8"onclick="getNumber(this.value)">8</button> <button class="btn" value="9"onclick="getNumber(this.value)">9</button> <button class="btn btn-primary" value="*" onclick="getOperation(this.value)">X</button> </div> <div class="row"> <button class="btn" value="4"onclick="getNumber(this.value)">4</button> <button class="btn" onclick="getNumber(this.value)" value="5">5</button> <button class="btn" value="6" onclick="getNumber(this.value)">6</button> <button class="btn btn-primary" value="-" onclick="getOperation(this.value)">—</button> </div> <div class="row"> <button class="btn" value="1" onclick="getNumber(this.value)">1</button> <button class="btn" value="2"onclick="getNumber(this.value)">2</button> <button class="btn" value="3"onclick="getNumber(this.value)">3</button> <button class="btn btn-primary" value="+" onclick="getOperation(this.value)">+</button> </div> <div class="row"> <button class="btn" value="0" onclick="getNumber(this.value)">0</button> <button class="btn" value="." onclick="getNumber(this.value)">.</button> <button class="btn btn-primary btn-equal" onclick="equal()">=</button> </div> </body> <p id="test"></p> <script src="js/index.js"></script>
</body>
</html>

Simple Calculator_Freecodecamp - Script Codes CSS Codes

.display{ margin-left:auto; margin-right:auto; border:2px solid #a1a1a1; height:40px; margin-top:30px; margin-bottom:20px; background:#dddddd; width:300px; font-size:20px;
}
.btn{ width:60px; margin-right:7.5px; margin-left:7.5px;
}
.btn-equal{ width:138px;
}
.row{ margin:6px;
}

Simple Calculator_Freecodecamp - Script Codes JS Codes

var store = [];
var result = 0;
var opera = '';
var string = '';
function getNumber(value){ string += value; document.getElementById("demo").innerHTML = string;
}
function getOperation(operation){ store.push(string); string = ''; opera = operation;
}
function equal(){ store.push(string); if(store.length==1) result = Number(store[0]); else { var value1 = Number(store[store.length-2]); var value2 = Number(store[store.length-1]); if(opera=="+") result = value1+value2; else if(opera=="-") result = value1-value2; else if(opera=="*") result = value1*value2; else if(opera=="/") result = value1/value2; else if(opera=="%") result = value1%value2; } document.getElementById("demo").innerHTML = result; string = ''; store = [];
}
function clear(){ string = ''; store = []; result = 0; document.getElementById("demo").innerHTML = result;
}
Simple Calculator_Freecodecamp - Script Codes
Simple Calculator_Freecodecamp - Script Codes
Home Page Home
Developer Shikun Ke
Username BarryKe
Uploaded November 28, 2022
Rating 3
Size 2,283 Kb
Views 8,096
Do you need developer help for Simple Calculator_Freecodecamp?

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!

Shikun Ke (BarryKe) Script Codes
Create amazing web content with AI!

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!