PDA

View Full Version : javascript error



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


<html>
<head>
<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){
grade="A";
} else if (total<=84 && total>=75){
grade="B";
} else if (total<=74 && total>=60){
grade="C";
} else if ( total<=59 && total>=0){
grade="D";
} else {
grade="*";
}

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);
}
-->
</script>
</head>

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


my codes didnt work n i dont know why

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

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

keyboard
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.