A calculator tool script written in HTML, CSS, and JavaScript:
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 20px;
}
.container {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
.result {
margin-top: 20px;
font-weight: bold;
}
.btn {
display: inline-block;
background-color: #4CAF50;
color: #fff;
text-decoration: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>Calculator</h1>
<input type="text" id="input" placeholder="Enter an expression" required>
<button class="btn" onclick="calculate()">Calculate</button>
<div class="result" id="result"></div>
</div>
<script>
function calculate() {
var expression = document.getElementById("input").value;
try {
var result = eval(expression);
document.getElementById("result").innerHTML = "Result: " + result;
} catch (error) {
document.getElementById("result").innerHTML = "Invalid expression";
}
}
</script>
</body>
</html>
0 Comments