Skip to content

Instantly share code, notes, and snippets.

@GulajavaMinistudio
Created February 9, 2018 02:42
Show Gist options
  • Select an option

  • Save GulajavaMinistudio/2cadbfc93798a845e3e906933cba84d6 to your computer and use it in GitHub Desktop.

Select an option

Save GulajavaMinistudio/2cadbfc93798a845e3e906933cba84d6 to your computer and use it in GitHub Desktop.
Kalkulator Nilai Sederhana HTML dan JS
<!DOCTYPE html>
<html>
<head>
<title>Latihan 8_1</title>
</head>
<body>
<h2>Hitung Nilai</h2>
<form name="form" action="javascript:void(0);">
<table>
<tr>
<td>Nilai Tugas (20%)</td>
<td><input type="text" name="ntgs"></td>
</tr>
<tr>
<td>Nilai UTS (35%)</td>
<td><input type="text" name="nuts"></td>
</tr>
<tr>
<td>Nilai UAS (45%)</td>
<td><input type="text" name="nuas"></td>
</tr>
<tr>
<td>Nilai Akhir</td>
<td><input type="text" name="nakhir" disabled></td>
</tr>
<tr>
<td>Nilai Huruf</td>
<td><input type="text" name="nhuruf" disabled></td>
</tr>
<tr>
<td>Predikat</td>
<td><input type="text" name="predikat" disabled></td>
</tr>
<tr>
<td><input type="submit" name="hasil" value="hitung" onclick="nilaiakhir()"></td>
<td><input type="reset" name="reset"></td>
</tr>
</table>
</form>
<script type="text/javascript">
/** kode fungsi nilai akhir */
function nilaiakhir(){
var ntgs = parseInt(document.form.ntgs.value);
var nuts = parseInt(document.form.nuts.value);
var nuas = parseInt(document.form.nuas.value);
var nhuruf = "";
var nakhir = (parseInt(ntgs)*20/100) + (parseInt(nuts)*35/100) + (parseInt(nuas)*45/100);
document.form.nakhir.value = nakhir;
if( nakhir > 80){
nhuruf = "A";
}
else if( nakhir > 70 ){
nhuruf = "B";
}
else if( nakhir > 60 ){
nhuruf = "C";
}
else if( nakhir > 40 ){
nhuruf = "D";
} else {
nhuruf = "E";
}
document.form.nhuruf.value = nhuruf;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment