View Full Version : javascript error

05-13-2015, 05:48 AM
hey guys newbie here, i got a task for my mid test

<title>Mencetak Grade Dengan Inputan Form</title>
<script type="text/javascript">
function hitunggrade() {
var nim=document.frmnilai.txtnim.value;
var nama=document.frmnilai.txtnama.value;
var absen=document.frmnilai.txtabsen.value;
var uts=document.frmnilai.txtuts.value;
var uas=document.frmnilai.txtuas.value;
var total=(10/100*absen)+(40/100*uts)+(50/100*uas);
var grade;
if (total<=100 && total>=85){
} else if (total<=84 && total>=75){
} else if (total<=74 && total>=60){
} else if ( total<=59 && total>=0){
} else {

document.write("NIM : " + nim);
document.write("<br>Nama : " + nama);
document.write("<br>Nilai Absen : " + absen);
document.write("<br>Nilai UTS : " + uts);
document.write("<br>Nilai UAS : " + uas);
document.write("<br>Nilai Anda : " + total);
document.write("<br>Grade Anda : " + grade);

<body><form name="frmnilai" method="post" action="">
<table border="0">
<td align="center" colspan="2">INPUT NILAI MAHASISWA</td>
<td>: <input name="txtnim" type="text" /></td>
<td>: <input name="txtnama" type="text" /></td>
<td>Nilai Absen</td>
<td>: <input name="txtabsen" type="text" /></td>
<td>Nilai UTS</td>
<td>: <input name="txtuts" type="text" /></td>
<td>Nilai UAS</td>
<td>: <input name="txtuas" type="text" /></td>
<td align="center"><input name="kirim" type="submit"
value="Hitung Grade" onClick= "hitunggrade()"/></td>

my codes didnt work n i dont know why

05-13-2015, 05:54 AM
What's a mid test?

05-13-2015, 06:05 AM
i mean midterm exam, sorry for my terrible english :D

05-13-2015, 10:29 AM
We would encourage you to try and solve any academic problems assigned with minimal help.

There aren't any javascript errors in the code you provided. There are some issues with it (listed below) but nothing that would prevent your code from running.

What is the code doing that it shouldn't be doing? (Or what isn't it doing that it should be doing)

Issue 1
Your code is lacking formatting. Try indenting your code as it will make debugging it a lot easier.

Issue 2
You're missing a valid Doctype at the beginning of your code.

Issue 3
The html comments around your javascript (to provide noscript support?) aren't necessary in any browser today.