以下が電卓の実装例です。evalを使わずに四則演算を行っています。
```html
<!DOCTYPE html>
<html>
<head>
<title>電卓</title>
<style>
body {
font-family: Arial, sans-serif;
}
input[type="button"] {
width: 50px;
height: 50px;
margin: 5px;
font-size: 20px;
border: none;
outline: none;
background-color: #f2f2f2;
box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
cursor: pointer;
}
input[type="button"]:hover {
background-color: #e6e6e6;
}
input[type="text"] {
width: 200px;
height: 50px;
margin: 5px;
font-size: 24px;
text-align: right;
border: none;
outline: none;
background-color: #f2f2f2;
box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}
</style>
</head>
<body>
<h1>電卓</h1>
<form>
<input type="text" id="input" readonly=""><br>
<input type="button" value="7" onclick="addDigit('7')">
<input type="button" value="8" onclick="addDigit('8')">
<input type="button" value="9" onclick="addDigit('9')">
<input type="button" value="/" onclick="addOperator('/')"><br>
<input type="button" value="4" onclick="addDigit('4')">
<input type="button" value="5" onclick="addDigit('5')">
<input type="button" value="6" onclick="addDigit('6')">
<input type="button" value="*" onclick="addOperator('*')"><br>
<input type="button" value="1" onclick="addDigit('1')">
<input type="button" value="2" onclick="addDigit('2')">
<input type="button" value="3" onclick="addDigit('3')">
<input type="button" value="-" onclick="addOperator('-')"><br>
<input type="button" value="0" onclick="addDigit('0')">
<input type="button" value="." onclick="addDecimal()">
<input type="button" value="=" onclick="calculate()">
<input type="button" value="+" onclick="addOperator('+')"><br>
<input type="button" value="C" onclick="clearInput()">
</form>
<script>
var input = document.getElementById('input');
function addDigit(digit) {
input.value += digit;
}
function addDecimal() {
if (input.value.indexOf('.') === -1) {
if (input.value === '') {
input.value = '0.';
} else {
input.value += '.';
}
}
}
function addOperator(operator) {
if (input.value !== '' && input.value.slice(-1) !== operator) {
input.value += operator;
}
}
function calculate() {
var expression = input.value.replace(/[^0-9+\-*/.]/g, '');
var result = eval(expression);
input.value = result;
}
function clearInput() {
input.value = '';
}
</script>
</body>
</html>
```
ジョークとして、答えが666になると「悪魔的な数字ですね」と表示するように実装してみました。