0% found this document useful (0 votes)
6 views

Basic Calculator (Green)

The document is an HTML code for a soft green-themed calculator web application. It includes styling for the calculator's layout, buttons, and display, as well as JavaScript functions for basic arithmetic operations and functionalities like clearing the display and calculating percentages. The calculator features a user-friendly interface with buttons for digits, operators, and functions.

Uploaded by

kendalltaylor111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Basic Calculator (Green)

The document is an HTML code for a soft green-themed calculator web application. It includes styling for the calculator's layout, buttons, and display, as well as JavaScript functions for basic arithmetic operations and functionalities like clearing the display and calculating percentages. The calculator features a user-friendly interface with buttons for digits, operators, and functions.

Uploaded by

kendalltaylor111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<!

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Soft Green Calculator</title>
<style>
body {
background-color: #e8f5e9; /* Very soft green background */
}
.calculator {
width: 250px;
margin: 0 auto;
border: 2px solid #4caf50; /* Bright green border */
background-color: #c8e6c9; /* Light green background for calculator
body */
padding: 10px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.display {
width: 90%;
margin: 5px auto;
padding: 10px;
font-size: 20px;
text-align: right;
background-color: #f1f8e9; /* Softer green for display */
border: 1px solid #81c784; /* Medium green border for display */
border-radius: 5px;
}
button {
width: 50px;
height: 50px;
margin: 3px;
font-size: 18px;
background-color: #a5d6a7; /* Soft green for buttons */
border: none;
border-radius: 5px;
color: #33691e; /* Dark green text color */
transition: background-color 0.3s, transform 0.1s;
}
button:hover {
background-color: #81c784; /* Slightly darker green on hover */
transform: scale(1.05);
}
button:active {
background-color: #66bb6a; /* Even darker green when pressed */
transform: scale(0.95);
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" class="display" id="display" readonly>
<div>
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('+')">+</button>
</div>
<div>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="handleMinus()">-</button>
</div>
<div>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('*')">*</button>
</div>
<div>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="appendToDisplay('.')">.</button>
<button onclick="appendToDisplay('/')">/</button>
<button onclick="computePercent()">%</button>
</div>
<div>
<button onclick="clearDisplay()">C</button>
<button onclick="computeFraction()">(</button>
<button onclick="calculate()">=</button>
</div>
</div>

<script>
// JavaScript functionality remains the same
let lastWasOperator = false;

function appendToDisplay(value) {
document.getElementById('display').value += value;
lastWasOperator = false;
}

function clearDisplay() {
document.getElementById('display').value = '';
lastWasOperator = false;
}

function calculate() {
try {
let result = eval(document.getElementById('display').value);
document.getElementById('display').value = result;
lastWasOperator = false;
} catch (e) {
document.getElementById('display').value = 'Error';
}
}

function computePercent() {
let display = document.getElementById('display');
let currentValue = parseFloat(display.value);
if (!isNaN(currentValue)) {
display.value = (currentValue / 100).toString();
}
lastWasOperator = true;
}
function computeFraction() {
let display = document.getElementById('display');
let currentValue = parseFloat(display.value);
if (!isNaN(currentValue) && currentValue !== 0) {
display.value = (1 / currentValue).toString();
} else {
display.value = 'Error';
}
lastWasOperator = true;
}

function handleMinus() {
let display = document.getElementById('display');
let currentValue = display.value;

if (currentValue === '' || lastWasOperator) {


appendToDisplay('-');
} else {
appendToDisplay('-');
}
lastWasOperator = true;
}
</script>
</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy