I’ve tried every possible loop combination (although i m new to javascripting) and nothing worked. This version has a working loop but stops after user enters nothing and hits OK. Prompt should be asking same question until nothing entered. At that point all the ‘results’ (whatever was entered in previous n prompts) should be retrieved and processed. End result should look like this (if ‘cs a 4’ and ‘bb b 3’ were entered for 2 prompts):
COURSE GRADE HOURS
cs a 4
bb b 3
Total grade points = 28
Number of hours = 7
GPA = 4.000
SCRIPT
[code=html]
<!doctype html>
<html>
<head>
<meta charset=”UTF-8″>
<title>Untitled Document</title>
</head>
<script type=”text/javascript”>
function getData(){
var input=0,
results=[];
while(input!==””){input = prompt(“Enter course name, grade and credit hours (e.g., ‘CS3520 A 4’ or click OK with no data to terminate.”);
input = input.split(” “);
if(input==””){
results.push({
course: input[0].trim(),
grade: input[1].trim(),
creditHours: parseInt(input[2], 10)
});}}
return results;
}
var app = function() {
var result, results,
COLUMN_SEPARATOR = “tt”;
document.writeln(“<pre>”);
results = getData();
document.writeln(“COURSE” + COLUMN_SEPARATOR + “GRADE” + COLUMN_SEPARATOR + “HOURS”);
for (var i = 0, j = results.length; i < j; i++) {
result = results[i];
document.writeln(result.course + COLUMN_SEPARATOR + result.grade + COLUMN_SEPARATOR + result.creditHours);
}
document.writeln();
computeGPA(results);
document.writeln(“</pre>”);
}
window.onload = app;
</script>
<body>
</body>
</html>