<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<style>
* {
margin: none;
font-size: 100%;
font-family: courier new;
}
*:focus {
outline: none;
}
#calculator {
box-shadow: 0px 0px 3px 4px rgba(0, 0, 0, 0.2);
}
#output {
height: 60px;
width: 100%;
font-size: 150%;
text-align: right;
color: black;
background-color: white;
border: none;
}
#content {
display: flex;
flex-wrap: wrap;
}
button {
background-color: black;
color: white;
width: 25%;
height: 50px;
float: left;
border: none;
}
@media only screen and (max-width: 600px) {
button {
height: 80px;
}
#output {
height: 80px;
}
}
</style>
<script>
function Write(n) {
if (output.value == undefined || output.value == 'Error') {
output.value = '';
}
output.value += n;
}
function Clear() {
output.value = '';
}
function calculate() {
if (output.value == '') {
output.value = '';
return;
}
let out = output.value;
out = out.replace(/mod/g, '%');
try {
output.value = eval(out).toFixed(9);
} catch {
output.value = 'Error';
}
}
</script>
</head>
<body>
<div id="calculator">
<input id="output" disabled>
<div id="content">
<button onclick="Write('(')">(</button>
<button onclick="Write(')')">)</button>
<button onclick="Write(' mod ')">mod</button>
<button style="background-color: gray" onclick="Clear()" id="clearButton">AC</button>
<br>
<button onclick="Write(7)">7</button>
<button onclick="Write(8)">8</button>
<button onclick="Write(9)">9</button>
<button onclick="Write(' / ')">/</button>
<br>
<button onclick="Write(4)">4</button>
<button onclick="Write(5)">5</button>
<button onclick="Write(6)">6</button>
<button onclick="Write(' * ')">*</button>
<br>
<button onclick="Write(1)">1</button>
<button onclick="Write(2)">2</button>
<button onclick="Write(3)">3</button>
<button onclick="Write(' - ')">-</button>
<br>
<button onclick="Write(0)">0</button>
<button onclick="Write('.')">.</button>
<button style="background-color:rgb(70, 70, 250)" onclick="calculate()">=</button>
<button onclick="Write(' + ')">+</button>
</div>
</div>
</body>
</html>
-------------------------------------------------------------------------------
Dan ini hasil Output/Terminalnya:
Oke, sekian semoga bermanfaat dan menambah wawasan. Terimakasih....
Kunjungin Juga Laman:
Ig: @bhiem04
Hp: 082114326091
Fb: Bhima Bramasta
Komentar
Posting Komentar