Program calculator has colorful and useful needs to be html and then one file
- User
Program calculator has colorful and useful needs to be html and then one file
- Assistant
- User
Make it a ti Texas instrument color edition sat approved
- Assistant
Program calculator has colorful and useful needs to be html and then one file
Make it a ti Texas instrument color edition sat approved
Sure! Below is a complete HTML file for a colorful and useful calculator. It includes HTML, CSS (for colorful styling), and JavaScript—all in one file. You can save this as calculator.html and open it in any modern browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Colorful Calculator</title>
<style>
/* Reset and base */
* {
box-sizing: border-box;
}
body {
background: linear-gradient(135deg, #667eea, #764ba2);
color: #fff;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.calculator {
background: #2c2f48;
border-radius: 20px;
box-shadow: 0 0 20px #5d5f9f;
padding: 20px;
width: 320px;
}
.display {
background: #1e213a;
border-radius: 15px;
height: 60px;
font-size: 2rem;
padding: 10px 20px;
margin-bottom: 15px;
text-align: right;
overflow-x: auto;
color: #fff;
user-select: none;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
}
button {
background: linear-gradient(145deg, #5d5f9f, #4a4e8f);
border: none;
border-radius: 15px;
color: white;
font-size: 1.25rem;
padding: 15px 0;
cursor: pointer;
box-shadow: 5px 5px 10px #40436a,
-5px -5px 10px #696cc7;
transition: 0.2s all ease-in-out;
}
button:hover {
background: linear-gradient(145deg, #7a7cba, #6365b1);
box-shadow: inset 5px 5px 10px #40436a,
inset -5px -5px 10px #696cc7;
}
button.operator {
background: linear-gradient(145deg, #ff6b6b, #ff8787);
color: white;
}
button.operator:hover {
background: linear-gradient(145deg, #ff8787, #ff4c4c);
}
button.equal {
background: linear-gradient(145deg, #6bcf6b, #87db87);
color: #1a1a1a;
grid-column: span 2;
}
button.equal:hover {
background: linear-gradient(145deg, #87db87, #4cba4c);
}
button.clear {
background: linear-gradient(145deg, #f3a683, #f7d794);
color: #4a2c2c;
}
button.clear:hover {
background: linear-gradient(145deg, #f7d794, #f3a683);
}
</style>
</head>
<body>
<div class="calculator" role="application" aria-label="Colorful calculator">
<div id="display" class="display" aria-live="polite" aria-atomic="true">0</div>
<div class="buttons">
<button class="clear" id="clear" aria-label="Clear all">C</button>
<button class="operator" data-operator="/" aria-label="Divide">÷</button>
<button class="operator" data-operator="*" aria-label="Multiply">×</button>
<button class="operator" data-operator="-" aria-label="Subtract">−</button>
<button data-number="7" aria-label="Number seven">7</button>
<button data-number="8" aria-label="Number eight">8</button>
<button data-number="9" aria-label="Number nine">9</button>
<button class="operator" data-operator="+" aria-label="Add">+</button>
<button data-number="4" aria-label="Number four">4</button>
<button data-number="5" aria-label="Number five">5</button>
<button data-number="6" aria-label="Number six">6</button>
<button id="backspace" aria-label="Backspace">⌫</button>
<button data-number="1" aria-label="Number one">1</button>
<button data-number="2" aria-label="Number two">2</button>
<button data-number="3" aria-label="Number three">3</button>
<button data-number="0" style="grid-column: span 2;" aria-label="Number zero">0</button>
<button data-number="." aria-label="Decimal point">.</button>
<button class="equal" id="equals" aria-label="Equals">=</button>
</div>
</div>
<script>
(function () {
const display = document.getElementById('display');
const buttons = document.querySelectorAll('button');
let currentInput = '';
let lastInputWasOperator = false;
function updateDisplay() {
display.textContent = currentInput || '0';
}
function isOperator(char) {
return ['+', '-', '*', '/'].includes(char);
}
buttons.forEach(button => {
button.addEventListener('click', () => {
const number = button.getAttribute('data-number');
const operator = button.getAttribute('data-operator');
if (button.id === 'clear') {
currentInput = '';
lastInputWasOperator = false;
updateDisplay();
return;
}
if (button.id === 'backspace') {
if (currentInput.length > 0) {
currentInput = currentInput.slice(0, -1);
if(currentInput.length > 0) {
const lastChar = currentInput[currentInput.length - 1];
lastInputWasOperator = isOperator(lastChar);
} else {
lastInputWasOperator = false;
}
}
updateDisplay();
return;
}
if (button.id === 'equals') {
if (currentInput === '') return;
try {
// Prevent evaluation if expression ends with operator
if (lastInputWasOperator) {
currentInput = currentInput.slice(0, -1);
}
let result = Function('"use strict";return (' + currentInput + ')')();
// Limiting floating decimals to max 8 digits
if(typeof result === 'number') {
result = Math.round((result + Number.EPSILON) * 1e8) / 1e8;
}
currentInput = result.toString();
lastInputWasOperator = false;
updateDisplay();
} catch {
currentInput = 'Error';
updateDisplay();
currentInput = '';
}
return;
}
if (number !== null) {
if (number === '.') {
// Don't allow multiple decimals in the current number chunk
let lastNumberChunk = currentInput.split(/[\+\-\*\/]/).pop();
if (lastNumberChunk.includes('.')) return;
if (currentInput === '' || lastInputWasOperator) {
currentInput += '0'; // e.g. clicking "." at start or just after operator becomes "0."
}
}
currentInput += number;
lastInputWasOperator = false;
updateDisplay();
return;
}
if (operator !== null) {
if (currentInput === '') {
// Don't allow operator first except minus for negative numbers
if (operator === '-') {
currentInput = operator;
lastInputWasOperator = true;
updateDisplay();
}
return;
}
if (lastInputWasOperator) {
// Replace the last operator with the new one
currentInput = currentInput.slice(0, -1) + operator;
} else {
currentInput += operator;
}
lastInputWasOperator = true;
updateDisplay();
return;
}
});
});
// Keyboard support
window.addEventListener('keydown', e => {
if (e.key >= '0' && e.key <= '9') {
document.querySelector(`button[data-number="${e.key}"]`).click();
e.preventDefault();
} else if (['+', '-', '*', '/'].includes(e.key)) {
document.querySelector(`button[data-operator="${e.key}"]`)?.click();
e.preventDefault();
} else if (e.key === 'Enter' || e.key === '=') {
document.getElementById('equals').click();
e.preventDefault();
} else if (e.key === 'Backspace') {
document.getElementById('backspace').click();
e.preventDefault();
} else if(e.key === 'Delete') {
document.getElementById('clear').click();
e.preventDefault();
} else if(e.key === '.') {
document.querySelector(`button[data-number="."]`).click();
e.preventDefault();
}
});
})();
</script>
</body>
</html>
Open the file in any browser, and you have a colorful and useful calculator in one file! Let me know if you want it extended with more advanced features.
Got it! You want a calculator that visually resembles a TI Texas Instruments calculator (color edition style), with SAT-appropriate functionality, presumably meaning basic arithmetic functions only (no advanced functions that are typically not allowed during the SAT exam).
Here’s what I will do:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>TI Calculator - SAT Edition</title>
<style>
/* Reset */
* {
box-sizing: border-box;
}
body {
background: #2a2a2a;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: 'Roboto Mono', monospace, monospace;
}
.calculator {
width: 350px;
background: #3b3b3b;
border-radius: 30px;
box-shadow:
inset 0 0 15px #232323,
0 10px 25px rgba(0,0,0,0.8);
padding: 20px 20px 30px;
user-select: none;
}
/* Screen */
.screen {
background: #1e1e1e;
height: 80px;
border-radius: 20px;
margin-bottom: 25px;
padding: 15px 20px;
color: #9fff9f;
font-size: 2.5rem;
text-align: right;
line-height: 1.2;
overflow-x: auto;
white-space: nowrap;
font-weight: 700;
box-shadow: inset 0 0 15px #65c465;
font-family: 'DS-Digital', monospace, monospace;
}
/* Buttons grid */
.buttons {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 15px;
}
/* Button basic style */
button {
border: none;
border-radius: 12px;
font-size: 1.25rem;
font-weight: 700;
cursor: pointer;
transition: all 0.15s ease-in-out;
box-shadow:
inset 0 -3px 0 #222,
0 3px 8px rgba(0,0,0,0.7);
}
button:active {
box-shadow:
inset 0 3px 5px #222,
0 1px 2px rgba(0,0,0,0.7);
transform: translateY(1px);
}
/* Color assignments based on TI color scheme */
/* Number buttons: medium gray dark */
button[data-number] {
background: #5a5a5a;
color: #e6e6e6;
box-shadow: inset 0 -3px 0 #444, 0 3px 8px #222;
}
button[data-number]:hover {
background: #6f6f6f;
}
/* Operator buttons: TI-style orange */
button.operator {
background: #ff9500;
color: #3d1f00;
box-shadow: inset 0 -3px 0 #b66e00, 0 3px 8px #b66e00;
}
button.operator:hover {
background: #ffc66a;
}
/* Clear and Backspace: TI-style teal */
button.clear {
background: #009688;
color: #e0f2f1;
box-shadow: inset 0 -3px 0 #00675b, 0 3px 8px #00675b;
}
button.clear:hover {
background: #33a79a;
}
/* Equals button: Lime green like TI */
button.equal {
background: #8bc34a;
color: #2f4600;
box-shadow: inset 0 -3px 0 #5a7a00, 0 3px 8px #5a7a00;
grid-column: span 2;
}
button.equal:hover {
background: #aedc76;
}
/* Zero button spans 2 columns */
button[data-number="0"] {
grid-column: span 2;
}
/* Font for digital display, optional (fallback if you want to add font-face) */
</style>
</head>
<body>
<div class="calculator" role="application" aria-label="Texas Instruments style calculator for SAT">
<div id="display" class="screen" aria-live="polite" aria-atomic="true">0</div>
<div class="buttons" role="group" aria-label="Calculator buttons">
<button class="clear" id="clear" aria-label="Clear all">C</button>
<button class="operator" data-operator="/" aria-label="Divide">÷</button>
<button class="operator" data-operator="*" aria-label="Multiply">×</button>
<button class="operator" data-operator="-" aria-label="Subtract">−</button>
<button class="operator" data-operator="+" aria-label="Add">+</button>
<button data-number="7" aria-label="Number seven">7</button>
<button data-number="8" aria-label="Number eight">8</button>
<button data-number="9" aria-label="Number nine">9</button>
<button id="backspace" aria-label="Backspace">⌫</button>
<button></button> <!-- empty cell for layout -->
<button data-number="4" aria-label="Number four">4</button>
<button data-number="5" aria-label="Number five">5</button>
<button data-number="6" aria-label="Number six">6</button>
<button></button> <!-- empty cell -->
<button></button> <!-- empty cell -->
<button data-number="1" aria-label="Number one">1</button>
<button data-number="2" aria-label="Number two">2</button>
<button data-number="3" aria-label="Number three">3</button>
<button data-number="0" aria-label="Number zero">0</button>
<button data-number="." aria-label="Decimal point">.</button>
<button class="equal" id="equals" aria-label="Equals">=</button>
</div>
</div>
<script>
(function () {
const display = document.getElementById('display');
const buttons = document.querySelectorAll('button');
let currentInput = '';
let lastInputWasOperator = false;
function updateDisplay() {
display.textContent = currentInput || '0';
}
function isOperator(char) {
return ['+', '-', '*', '/'].includes(char);
}
buttons.forEach(button => {
button.addEventListener('click', () => {
const number = button.getAttribute('data-number');
const operator = button.getAttribute('data-operator');
if (button.id === 'clear') {
currentInput = '';
lastInputWasOperator = false;
updateDisplay();
return;
}
if (button.id === 'backspace') {
if (currentInput.length > 0) {
currentInput = currentInput.slice(0, -1);
if(currentInput.length > 0) {
const lastChar = currentInput[currentInput.length - 1];
lastInputWasOperator = isOperator(lastChar);
} else {
lastInputWasOperator = false;
}
}
updateDisplay();
return;
}
if (button.id === 'equals') {
if (currentInput === '') return;
try {
// Prevent evaluation if expression ends with operator
if (lastInputWasOperator) {
currentInput = currentInput.slice(0, -1);
}
let result = Function('"use strict";return (' + currentInput + ')')();
if(typeof result === 'number') {
// Round floating decimals to max 8 decimals
result = Math.round((result + Number.EPSILON) * 1e8) / 1e8;
}
currentInput = result.toString();
lastInputWasOperator = false;
updateDisplay();
} catch {
currentInput = 'Error';
updateDisplay();
currentInput = '';
}
return;
}
if (number !== null) {
if (number === '.') {
// Prevent multiple decimals in one number chunk
let parts = currentInput.split(/[\+\-\*\/]/);
let lastNumberChunk = parts[parts.length - 1];
if (lastNumberChunk.includes('.')) return;
// Add leading zero before decimal if empty or operator before
if (currentInput === '' || lastInputWasOperator) {
currentInput += '0';
}
}
currentInput += number;
lastInputWasOperator = false;
updateDisplay();
return;
}
if (operator !== null) {
if (currentInput === '') {
// Only allow minus at start for negatives
if (operator === '-') {
currentInput = operator;
lastInputWasOperator = true;
updateDisplay();
}
return;
}
if (lastInputWasOperator) {
// Swap last operator with this operator
currentInput = currentInput.slice(0, -1) + operator;
} else {
currentInput += operator;
}
lastInputWasOperator = true;
updateDisplay();
return;
}
});
});
// Keyboard support
window.addEventListener('keydown', e => {
if (e.key >= '0' && e.key <= '9') {
document.querySelector(`button[data-number="${e.key}"]`).click();
e.preventDefault();
} else if (['+', '-', '*', '/'].includes(e.key)) {
document.querySelector(`button[data-operator="${e.key}"]`)?.click();
e.preventDefault();
} else if (e.key === 'Enter' || e.key === '=') {
document.getElementById('equals').click();
e.preventDefault();
} else if (e.key === 'Backspace') {
document.getElementById('backspace').click();
e.preventDefault();
} else if (e.key === 'Delete') {
document.getElementById('clear').click();
e.preventDefault();
} else if (e.key === '.') {
document.querySelector(`button[data-number="."]`).click();
e.preventDefault();
}
});
})();
</script>
</body>
</html>
ti-sat-calculator.htmlIf you'd like a different TI model style (e.g. TI-30X IIS or TI-84 Plus CE exact key layout), or additional requested features, just let me know!
Not yet included in a published release.