calculator.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Scientific Calculator</title> <style> body { font-family: Arial, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background-color: #f4f4f4; } #calculator { border: 1px solid #ccc; border-radius: 8px; padding: 20px; background-color: white; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } #display { width: 100%; height: 40px; text-align: right; font-size: 24px; border: 1px solid #ccc; margin-bottom: 10px; padding: 5px; border-radius: 5px; } button { width: 60px; height: 60px; font-size: 20px; margin: 5px; border: none; border-radius: 5px; background-color: #6200ea; color: white; cursor: pointer; transition: background-color 0.3s; } button:hover { background-color: #3700b3; } .row { display: flex; } </style> </head> <body> <div id="calculator"> <input type="text" id="display" disabled> <div class="row"> <button onclick="appendToDisplay('7')">7</button> <button onclick="appendToDisplay('8')">8</button> <button onclick="appendToDisplay('9')">9</button> <button onclick="appendToDisplay('/')">/</button> </div> <div class="row"> <button onclick="appendToDisplay('4')">4</button> <button onclick="appendToDisplay('5')">5</button> <button onclick="appendToDisplay('6')">6</button> <button onclick="appendToDisplay('*')">*</button> </div> <div class="row"> <button onclick="appendToDisplay('1')">1</button> <button onclick="appendToDisplay('2')">2</button> <button onclick="appendToDisplay('3')">3</button> <button onclick="appendToDisplay('-')">-</button> </div> <div class="row"> <button onclick="appendToDisplay('0')">0</button> <button onclick="appendToDisplay('.')">.</button> <button onclick="calculateResult()">=</button> <button onclick="appendToDisplay('+')">+</button> </div> <div class="row"> <button onclick="clearDisplay()">C</button> </div> </div> <script> function appendToDisplay(value) { document.getElementById("display").value += value; } function clearDisplay() { document.getElementById("display").value = ""; } function calculateResult() { const display = document.getElementById("display"); try { const result = eval(display.value); display.value = result; } catch (error) { display.value = "Error"; } } </script> </body> </html>