Menghitung nilai Rata-rata dengan javascript
Yoow, kali ini ane mau ngasih tau cara bikin program javascript untuk meghitung nilai rata-rata. gak usah banyak basa-basi deh langsung saja kita lihat scriptnya
Script :
<html>
<head>
<title> Muhamad Ahmadin </title>
<style>
fieldset {width:400px;
background-color:#333;
border-bottom:11px solid maroon;
border-radius:20px 10px;
margin:auto;
transition:2s;}
fieldset:hover {box-shadow:5px 8px 11px black;
padding:10px;
margin:auto;}
.Zoedoel { font-weight:bold;
font-family:consolas;
padding:15px 10px;
}
.Infoet { text-align:center;
border-color:maroon;
color:blue;
}
.WadahInput { padding:3px 6px;
background-color:#333;;
}
button {background-color:maroon;
color:white;
font-family:courier;
border:1px solid maroon;
border-radius:5px 5px;
transition:3s;
cursor:pointer;
padding:8px;}
button:hover {padding:20px;
background-color:firebrick;
color:white;
font-weight:bold;
font-size:16px;
border-radius:10px 5px;}
table, th, td {background-color:#333;
color:white;}
</style>
</head>
<body>
<br><center>
<fieldset>
<form name="form">
<table border="2" style="border-collapse:collapse;text-align:center;border:3px solid maroon;margin-left:19px;">
<tr>
<td class="Zoedoel"> Nilai 1 </td>
<td class="Zoedoel"> Nilai 2 </td>
<td class="Zoedoel"> Nilai 3 </td>
<td class="Zoedoel"> Nilai 4 </td>
<td class="Zoedoel"> Nilai 5 </td>
<td class="Zoedoel"> Nilai 6 </td>
<td class="Zoedoel"> Nilai 7 </td>
<td class="Zoedoel"> Nilai 8 </td>
</tr>
<tr>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka1" size="4" value="2.3"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka2" size="4" value="3.4"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka3" size="4" value="4.5"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka4" size="4" value="6.7"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka5" size="4" value="7.8"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka6" size="4" value="8.9"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka7" size="4" value="9.10"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka8" size="4" value="10.1"> </td>
</tr>
</table>
</form>
<button type="button" onclick="cek()"> Lihat Nilai Rata-Rata </button>
<h3 style="border:2px solid maroon;width:200px;text-align:center;color:white;" id="tampil"> </h3>
<br></fieldset>
<br>
<div style="border-top:6px solid #800000;
width:60%;
margin:auto;
border-radius:111px;"> </div> <br><br>
<script>
function cek() {
var a=form.angka1.value;
var b=form.angka2.value;
var c=form.angka3.value;
var d=form.angka4.value;
var e=form.angka5.value;
var f=form.angka6.value;
var g=form.angka7.value;
var h=(a-(-b)-(-c)-(-d)-(-e)-(-f)-(-g))/7; //rumus ini belum pasti benar. soalnya Dadin gk tau hoho
document.getElementById("tampil").innerHTML = h.toFixed(1) ;
}
</script> </center>
</body>
</html>
<head>
<title> Muhamad Ahmadin </title>
<style>
fieldset {width:400px;
background-color:#333;
border-bottom:11px solid maroon;
border-radius:20px 10px;
margin:auto;
transition:2s;}
fieldset:hover {box-shadow:5px 8px 11px black;
padding:10px;
margin:auto;}
.Zoedoel { font-weight:bold;
font-family:consolas;
padding:15px 10px;
}
.Infoet { text-align:center;
border-color:maroon;
color:blue;
}
.WadahInput { padding:3px 6px;
background-color:#333;;
}
button {background-color:maroon;
color:white;
font-family:courier;
border:1px solid maroon;
border-radius:5px 5px;
transition:3s;
cursor:pointer;
padding:8px;}
button:hover {padding:20px;
background-color:firebrick;
color:white;
font-weight:bold;
font-size:16px;
border-radius:10px 5px;}
table, th, td {background-color:#333;
color:white;}
</style>
</head>
<body>
<br><center>
<fieldset>
<form name="form">
<table border="2" style="border-collapse:collapse;text-align:center;border:3px solid maroon;margin-left:19px;">
<tr>
<td class="Zoedoel"> Nilai 1 </td>
<td class="Zoedoel"> Nilai 2 </td>
<td class="Zoedoel"> Nilai 3 </td>
<td class="Zoedoel"> Nilai 4 </td>
<td class="Zoedoel"> Nilai 5 </td>
<td class="Zoedoel"> Nilai 6 </td>
<td class="Zoedoel"> Nilai 7 </td>
<td class="Zoedoel"> Nilai 8 </td>
</tr>
<tr>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka1" size="4" value="2.3"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka2" size="4" value="3.4"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka3" size="4" value="4.5"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka4" size="4" value="6.7"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka5" size="4" value="7.8"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka6" size="4" value="8.9"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka7" size="4" value="9.10"> </td>
<td class="wadahInput"> <input class="Infoet" type="text" name="angka8" size="4" value="10.1"> </td>
</tr>
</table>
</form>
<button type="button" onclick="cek()"> Lihat Nilai Rata-Rata </button>
<h3 style="border:2px solid maroon;width:200px;text-align:center;color:white;" id="tampil"> </h3>
<br></fieldset>
<br>
<div style="border-top:6px solid #800000;
width:60%;
margin:auto;
border-radius:111px;"> </div> <br><br>
<script>
function cek() {
var a=form.angka1.value;
var b=form.angka2.value;
var c=form.angka3.value;
var d=form.angka4.value;
var e=form.angka5.value;
var f=form.angka6.value;
var g=form.angka7.value;
var h=(a-(-b)-(-c)-(-d)-(-e)-(-f)-(-g))/7; //rumus ini belum pasti benar. soalnya Dadin gk tau hoho
document.getElementById("tampil").innerHTML = h.toFixed(1) ;
}
</script> </center>
</body>
</html>
Hasilnya :
Oke itu semua dari saya,,, semoga bermanfaat ya gan.