Membuat Websita Dengan Menggunakan
Bahasa HTML, Javascript dan PHP
Soal 1
Membuat perhitungan bunga sebuah bank
<!DOCTYPE html><html>
<head>
<title>Hitung Bunga Tabungan</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript"></script>
</head>
<body>
<div class="container">
<br>
<h1>Pemrograman Web 1</h1>
<hr style="border-color:orange;">
<form action="" method="post" style="padding-right: 900px">
Saldo Awal <input type="saldoAwal" name="saldoAwal" class="form-control" value="2000000" readonly>
Suku Bunga <input type="bunga" name="bunga" class="form-control" value="3" readonly>
Jumlah Bulan <input type="bulan" name="bulan" class="form-control" value="11" readonly><br>
<table width="200" cellspacing="0" cellpading="3">
<tr>
<td>
<button type="submit" name="hitung" class="btn btn-primary" style="background-color: orange; color: black; width: 90px;">hitung</button>
</td>
</tr>
</table>
</form>
<!-- memberikan nilai kosong pada variabel -->
<?php
$saldoAwal = 0;
$bunga = 0;
$bulan = 0;
?>
<!-- ------------------------------------------- -->
<?php if (isset($_POST['hitung'])): ?>
<?php $saldoAwal = $_POST['saldoAwal']; ?>
<?php $bunga = $_POST['bunga']; ?>
<?php $bulan = $_POST['bulan']; ?>
<?php endif ?>
<!-- pengkodisian saldo awal agar tidak error saat pemberian $variabel = number_format(,) -->
<?php
echo "============================================================================="."<br>";
echo "informasi :"."<br>";
if ($saldoAwal == FALSE) {
echo "Saldo Awal = ".$saldoAwal."<br>";
}else{
echo "Saldo Awal = ".$saldoAwalFormat = number_format($saldoAwal,2)."<br>";
}
// ------------------------------------------------------------------------------------------
echo "Suku Bunga = " .$bunga."%"."<br>";
echo "Jumlah Bulan = " .$bulan." bulan"."<br>";
echo "=============================================================================="."<br>";
echo "hasil perhitungan :"."<br>";
// menhitung jumlah saldo tiap bulan yang sudah ditambahkan dengan bunga
$saldoBertambah = $saldoAwal;
for ($x=1; $x <= $bulan; $x++) {
$hasilbunga = (($saldoBertambah * $bunga) / 100 );
$saldoBertambah = $saldoBertambah + $hasilbunga;
echo "Saldo Awal Bulan:$x = " .$saldoBertambahFormat = number_format($saldoBertambah,2); echo " | Bunga = " .number_format($hasilbunga,2)."%"; echo " | Saldo Akhir Bulan ke:$x = " .$saldoBertambahFormat = number_format($saldoBertambah,2)."<br>";
}
// ----------------------------------------------------------------------------------------------------
echo "=============================================================================="."<br>";
?>
</div>
</body>
</html>
Soal 2
Menghitung ruang bangun krucut
file html
<html><head>
<title>Menghitung Luas Alas Kerucut</title>
<script type="text/javascript">
function hitungluas(){
phi=document.getElementById("phi").value;
r=document.getElementById("r").value;
luas=(phi*r*r);
hasil = luas.toFixed(2);
document.getElementById("hasil").value=hasil;
}
</script>
</head>
<body>
<form>
<h4 style="margin-left:10px;"><u>Menghitung Luas Alas Kerucut</u></h4>
<table cellpadding="5" cellspacing="5">
<tr>
<td>Phi</td>
<td>:</td>
<td><input type="text" id="phi" name="phi" value="3.14" readonly></td>
</tr>
<tr>
<td>r</td>
<td>:</td>
<td><input type="text" id="r" name="tinggi"></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="button" value="hitung" onClick="hitungluas()"></td>
</tr>
<tr>
<td>Luas</td>
<td>:</td>
<td><input type="text" id="hasil" name="hasil" disabled="true" size="5"></td>
</tr>
</table>
</form>
</body>
</html>
File Javascript
<!DOCTYPE html><html>
<head>
<title>Luas Alas dan Permukaan Kerucut</title>
</head>
<body>
<h1>Masukan Data</h1>
<form action="" method="GET">
Nilai Data
<input type="text" name="txnilai" id="txr">
<input type="text" name="txnilai" id="txs">
<input type="button" name="txcmd" value="Ambil Data" onclick="ambildata();">
</form>
<script language="JavaScript">
function ambildata (){
var nialidata = document.getElementById('txnilaidata').value;
alert("Nilai Dari Data Form Adalah: " + nialidata);
}
</script>
</body>
</html>
File PHP
<?php define("pi", 3.14);
$r = 10;
$s = 17;
$luasalas = pi * $r * $r;
$luaspermukaan = $luasalas + (pi * $r * $s);
print "luas alas = ". $luasalas."<br>";
print "luas permukaan = ".$luaspermukaan;
?>
</div>
</body>
</html>
Hasil di browser