Sharp Scientific Calculator
.sharp-calc-container {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
color: #333;
}
.calc-box {
background: #333;
padding: 20px;
border-radius: 10px;
box-shadow: 0 10px 25px rgba(0,0,0,0.2);
max-width: 400px;
margin: 0 auto 30px;
}
.calc-display {
width: 100%;
height: 60px;
background: #a1b5a1;
border: 2px solid #888;
border-radius: 4px;
margin-bottom: 15px;
font-family: 'Courier New', Courier, monospace;
font-size: 24px;
text-align: right;
padding: 10px;
box-sizing: border-box;
color: #1a1a1a;
}
.calc-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
.calc-btn {
padding: 15px 5px;
font-size: 16px;
font-weight: bold;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background 0.2s;
}
.btn-num { background: #666; color: white; }
.btn-op { background: #f39c12; color: white; }
.btn-sci { background: #444; color: #eee; font-size: 13px; }
.btn-clear { background: #e74c3c; color: white; }
.btn-equal { background: #27ae60; color: white; grid-column: span 2; }
.calc-btn:hover { opacity: 0.8; }
.sharp-article h2 { color: #2c3e50; margin-top: 25px; border-bottom: 2px solid #f39c12; padding-bottom: 5px; }
.sharp-article p { line-height: 1.6; font-size: 16px; margin-bottom: 15px; }
.sharp-article ul { margin-bottom: 15px; }
.sharp-article li { margin-bottom: 8px; }
.example-box { background: #fff; border-left: 5px solid #27ae60; padding: 15px; margin: 20px 0; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
function appendChar(char) {
var display = document.getElementById('sharpDisplay');
if (display.value === "0" || display.value === "Error") {
display.value = char;
} else {
display.value += char;
}
}
function clearCalc() {
document.getElementById('sharpDisplay').value = "0";
}
function scientificAction(type) {
var display = document.getElementById('sharpDisplay');
var val = parseFloat(display.value);
if (isNaN(val)) {
display.value = "Error";
return;
}
var result;
switch(type) {
case 'sin':
result = Math.sin(val * Math.PI / 180);
break;
case 'cos':
result = Math.cos(val * Math.PI / 180);
break;
case 'tan':
result = Math.tan(val * Math.PI / 180);
break;
case 'log':
result = Math.log10(val);
break;
case 'ln':
result = Math.log(val);
break;
default:
result = "Error";
}
display.value = Number(result.toFixed(8)).toString();
}
function runCalculation() {
var display = document.getElementById('sharpDisplay');
try {
// Using a simple eval for basic arithmetic strings
// Replaces X with * just in case, though buttons use *
var expression = display.value;
var result = eval(expression);
if (result === Infinity || isNaN(result)) {
display.value = "Error";
} else {
display.value = Number(result.toFixed(8)).toString();
}
} catch (e) {
display.value = "Error";
}
}