Fantasy Adventure Scientific Calculator - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Fantasy Adventure Scientific Calculator</title> <style> body { font-family: 'Arial', sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #1e1e1e; margin: 0; color: #fff; } .calculator { background-color: #2e2e2e; border-radius: 10px; box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); overflow: hidden; width: 300px; } .screen { background-color: #3e3e3e; color: #f8de7e; font-size: 2rem; padding: 10px; text-align: right; word-wrap: break-word; overflow-wrap: break-word; min-height: 60px; } .buttons { display: grid; grid-template-columns: repeat(4, 1fr); } button { background-color: #4e4e4e; border: none; color: #fff; cursor: pointer; font-size: 1.5rem; padding: 20px 0; transition: background-color 0.3s ease; } button:hover { background-color: #5e5e5e; } button.operator { background:linear-gradient(#f8de7e, #ffff00); color: #000; } button.special { background:linear-gradient(#f8de7e, #ffff00); color: #000; } button.equal { background:linear-gradient(#f8de7e, #ffff00); color: #000; grid-column: span 1; } </style> </head> <body> <div class="calculator"> <div class="screen" id="screen">0</div> <div class="buttons"> <button type="button" class="operator">C</button> <button type="button" class="operator">±</button> <button type="button" class="operator">%</button> <button type="button" class="operator">÷</button> <button type="button">7</button> <button type="button">8</button> <button type="button">9</button> <button type="button" class="operator">x</button> <button type="button">4</button> <button type="button">5</button> <button type="button">6</button> <button type="button" class="operator">-</button> <button type="button">1</button> <button type="button">2</button> <button type="button">3</button> <button type="button" class="operator">+</button> <button type="button" class="special">π</button> <button type="button">0</button> <button type="button">.</button> <button type="button" class="equal">=</button> </div> </div> <script> document.addEventListener('DOMContentLoaded', function() { const screen = document.getElementById('screen'); const buttons = document.querySelectorAll('.buttons button'); let calculation = ''; let currentInput = ''; let lastOperator = ''; function updateScreen(value) { screen.textContent = value; } buttons.forEach(button => { button.addEventListener('click', () => { const buttonText = button.textContent; if (buttonText === 'C') { calculation = ''; currentInput = ''; lastOperator = ''; updateScreen('0'); } else if (buttonText === '±') { if (currentInput) { currentInput = (parseFloat(currentInput) * -1).toString(); updateScreen(currentInput); } } else if (buttonText === '%') { if (currentInput) { currentInput = (parseFloat(currentInput) / 100).toString(); updateScreen(currentInput); } } else if (buttonText === 'π') { currentInput = Math.PI.toString(); updateScreen(currentInput); } else if (buttonText === '=') { if (currentInput && lastOperator) { calculation += currentInput; try { calculation = eval(calculation).toString(); updateScreen(calculation); currentInput = calculation; calculation = ''; lastOperator = ''; } catch (e) { updateScreen('Error'); calculation = ''; currentInput = ''; lastOperator = ''; } } } else if (['÷', 'x', '-', '+'].includes(buttonText)) { if (currentInput) { calculation += currentInput; calculation += buttonText === '÷' ? '/' : buttonText === 'x' ? '*' : buttonText; lastOperator = buttonText; currentInput = ''; updateScreen(buttonText); } } else { currentInput += buttonText; updateScreen(currentInput); } }); }); }); </script> </body> </html>