<!DOCTYPE html>
<html>
<head>
<title>Calculadora Científica</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.calculator {
width: 400px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
input[type="text"] {
width: 79%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.btn {
display: inline-block;
width: 70px;
height: 40px;
margin: 5px;
text-align: center;
line-height: 40px;
border: 1px solid #ccc;
border-radius: 5px;
cursor: pointer;
}
#equals {
background-color: #abf7ad;
color: white;
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<div>
<div class="btn" onclick="appendText('7')">7</div>
<div class="btn" onclick="appendText('8')">8</div>
<div class="btn" onclick="appendText('9')">9</div>
<div class="btn" onclick="appendText('/')">/</div>
</div>
<div>
<div class="btn" onclick="appendText('4')">4</div>
<div class="btn" onclick="appendText('5')">5</div>
<div class="btn" onclick="appendText('6')">6</div>
<div class="btn" onclick="appendText('*')">*</div>
</div>
<div>
<div class="btn" onclick="appendText('1')">1</div>
<div class="btn" onclick="appendText('2')">2</div>
<div class="btn" onclick="appendText('3')">3</div>
<div class="btn" onclick="appendText('-')">-</div>
</div>
<div>
<div class="btn" onclick="appendText('0')">0</div>
<div class="btn" onclick="appendText('.')">.</div>
<div class="btn" id="equals" onclick="calculate()">=</div>
<div class="btn" onclick="appendText('+')">+</div>
</div>
<div>
<div class="btn" onclick="appendText('Math.sqrt(')">√</div>
<div class="btn" onclick="appendText('Math.pow(')">x²</div>
<div class="btn" onclick="appendText('Math.pow(')">x³</div>
<div class="btn" onclick="appendText('Math.pow(')">xʸ</div>
<div class="btn" onclick="appendText('Math.exp(')">eˣ</div>
<div class="btn" onclick="appendText('Math.log10(')">log</div>
<div class="btn" id="clear" onclick="clearDisplay()">C</div>
<div class="btn" onclick="appendText('(')">(</div>
<div class="btn" onclick="appendText(')')">)</div>
</div>
</div>
<script>
function appendText(text) {
const display = document.getElementById('display');
display.value += text;
}
function calculate() {
const display = document.getElementById('display');
try {
display.value = eval(display.value);
} catch (error) {
display.value = 'Error';
}
}
function clearDisplay() {
const display = document.getElementById('display');
display.value = '';
}
</script>
</body>
</html>