Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var display = document.formNilai.formTeks;
function btn(num)
{
display.value += num;
}

function hitung()
{
display.value = eval(display.value);
}

function bcksp()
{
display.value = display.value.substr(0,display.value.length-1);
}

function clr()
{
display.value ="";
}
43 changes: 40 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,47 @@
<html lang="en">
<head>
<title>Exercise 2</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<center>
<h1>Kalkulator</h1>
</center>
<div class="priority">
<h2>Kalkulator</h2>
<form name="formNilai">
<input type="text" name="formTeks" autocomplete="off">
</form>
<table>
<tr>
<td><input type="button" value="1" onclick="btn(1)"></td>
<td><input type="button" value="2" onclick="btn(2)"></td>
<td><input type="button" value="3" onclick="btn(3)"></td>
<td><input type="button" value="*" onclick="btn('*')"></td>
</tr>
<tr>
<td><input type="button" value="4" onclick="btn(4)"></td>
<td><input type="button" value="5" onclick="btn(5)"></td>
<td><input type="button" value="6" onclick="btn(6)"></td>
<td><input type="button" value="/" onclick="btn('/')"></td>
</tr>
<tr>
<td><input type="button" value="7" onclick="btn(7)"></td>
<td><input type="button" value="8" onclick="btn(8)"></td>
<td><input type="button" value="9" onclick="btn(9)"></td>
<td><input type="button" value="-" onclick="btn('-')"></td>
</tr>
<tr>
<td><input type="button" value="0" onclick="btn(0)"></td>
<td><input type="button" value="." onclick="btn('.')"></td>
<td><input type="button" value="C" onclick="clr()"></td>
<td><input type="button" value="+" onclick="btn('+')"></td>
</tr>
<tr>
<td colspan="5"><input type="button" value="=" style="width : 100%" onclick="hitung()"></td>
</tr>
<tr>
<td colspan="5"><input type="button" value="Backspace" style="width : 100%" onclick="bcksp()"></td>
</tr>
</table>
</div>
<script type="text/javascript" src="calculator.js"></script>
</body>
</html>
49 changes: 49 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
* {
margin: 0;
padding: 0;
}
.priority
{
background-color:yellowgreen;
position: absolute;
padding: 10px;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
border-radius: 5px;
box-shadow: 5px 4px 5px #A5A5A5FF;
}
h2
{
text-align: center;
font-family: sans-serif;
}
table
{
width: 100%;
}
form input
{
font-size: 22px;
margin: 5px;
padding: 5px;
height: 66px;
text-align: right;
}
table td input
{
width : 100%;
background-color :burlywood;
padding : 5px;
font-size : 22px;
cursor : pointer;
border : 2px solid #000;
}
table td input:hover
{
border : 2px solid #DAA67BFF;
}
body
{
background-color: blueviolet;
}