Cara Memeriksa Kode JavaScript saya
<!DOCTYPE html>
<html>
<head> </head>
<style>
table, tr,th, td {
border: 1px solid;
}
</style>
<body>
<center>
<h1>CGPA CALCULATOR</h1>
<table>
<tr>
<th style="color: black;">COURSE CODE </th>
<th style="color: black;"> COURSE TITLE</th>
<th style="color: black;"> UNITS</th>
<th style="color: black;"> MARK</th>
<th style="color: black;"> GRADE</th>
</tr>
<tr>
<td>ITEC202</td>
<td>Operating systems</td>
<td>4</td>
<td><input type="text" id="t1" value=""></td>
<td id="g1"></td>
</tr>
<tr>
<td>ITEC224</td>
<td>Database programming</td>
<td>4</td>
<td><input type="text" id="t2" value=""></td>
<td id="g2"></td>
</tr>
<tr>
<td>ITEC230</td>
<td>Rich Internet Application Development</td>
<td>4</td>
<td><input type="text" id="t3" value=""></td>
<td id="g3"></td>
</tr>
<tr>
<td>ITEC243</td>
<td>Rich Internet Application Development</td>
<td>4</td>
<td><input type="text" id="t4" value=""></td>
<td id="g4"></td>
</tr>
<tr>
<td>ITEC259</td>
<td>Digital Logic Design</td>
<td>4</td>
<td><input type="text" id="t5" value=""></td>
<td id="g5"></td>
</tr>
<tr>
<td colspan="3"><center><input type="button" id="butn1" value="Calculate CGPA" ></center></td>
<th>CGPA:</th>
<td id="2001"></td>
</tr>
</table>
</center>
</body>
<script>
function CalculateCGPA(){
var os=document.getElementById("t1").value;
if(os="")
os=0;
var gs=document.getElementById("t2").value;
if(gs="")
gs=0;
var dc=document.getElementById("t3").value;
if(dc="")
dc=0;
var xus=document.getElementById("t4").value;
if(xus="")
xus=0;
var abd=document.getElementById("t5").value;
if(abd="")
abd=0;
document.getElementById("g1").innerHTML=letterGrade(os);
document.getElementById("g2").innerHTML=letterGrade(gs);
document.getElementById("g3").innerHTML=letterGrade(dc);
document.getElementById("g4").innerHTML=letterGrade(xus);
document.getElementById("g5").innerHTML=letterGrade(abd);
var cgpa=(4*gradeWeight(os)+4*gradeWeight(gs)+4*gradeWeight(dc)+4*gradeWeight(xus)+4*gradeWeight(abd))/20;
document.getElementById("2001").innerHTML=document.write(cgpa);
}
function letterGrade(mark){
mark=parseInt(mark);
if(mark>=90)
return 'A';
if(mark>=85)
return 'A-';
if(mark>=80)
return 'B+';
if(mark>=75)
return 'B';
if(mark>=70)
return 'B-';
if(mark>=65)
return 'C+';
if(mark>=60)
return 'C';
if(mark>=56)
return 'C-';
if(mark>=53)
return 'D+';
if(mark>=50)
return 'D';
if(mark>=40)
return 'D-';
if(mark<=39.9)
return 'F';
}
function gradeWeight(mark){
if(mark>=90)
return 4.0;
if(mark>=85)
return 3.7;
if(mark>=80)
return 3.3;
if(mark>=75)
return 3.0;
if(mark>=70)
return 2.7;
if(mark>=65)
return 2.3;
if(mark>=60)
return 2.0;
if(mark>=56)
return 1.7;
if(mark>=53)
return 1.3;
if(mark>=50)
return 1.0;
if(mark>=40)
return 0.7;
if(mark<=39.9)
return 0.0;
}
document.getElementById("butn1").addEventListener("click", CalculateCGPA);
</script>
</html>
Husna Hassan