...

View Full Version : Need suggestions on >.o this code

seulki
12-14-2010, 09:45 AM
Ello~ I was just wondering if ^^ anyone could look at this code and tell me where there are errors... or any suggestions so i could clean up the code a bit, so it would work :] that way i could figure it out :D Thank you for your time~ ^_^

<html>
<head> <title> RETAKES </title>
<script type="text/javascript" src="http://dave-reed.com/book/random.js"> </script>
<script type="text/javascript">

function TakeTest( )
// simulates a student's test taking by generating random values for the grades
// and allowing up to a certain number of retakes displaying the apropriate messages
// algorithm:
// set up: max num of retakes at 3 and passing grade at 70
// generate a random grade between 1-100 and
// IF equal or greater than the passing grade display "Your initial passing grade: ..."
// ELSE: setup the count of retakes at 0
// DO: increment the count for retakes
// generate a random grade between 1-100 and display "Your retake grade: " ..."
// WHILE: the retake count is less or equal to the max number of retakes AND the grade IS NOT a passing grade
// afterwards: either the iteration ended with a passing grade OR not, so check for which condition occurred
// IF after the retakes the grade is a passing grade then display "You Passed with a grade of: ... after ... retake(s)"
// ELSE display "You still failed after " ... " retakes."
{
retake = 0;
grade = randomInt(1, 100);
document.getElementById("text").value = document.getElementById("text").value + "Your initial passing grade: " + grade;
}
else {
retake = 0;
do {
retake++;
grade = randomInt(1, 100);
document.getElementById("text").value = document.getElementById("text").value + "Your retake grade: " + grade;
while (retake <= 3 && grade != passGrade)
}
}
if (retake <= 3 && grade == passGrade) {
document.getElementById("text").value = document.getElementById("text").value + "You passed with a grade of " + grade + " after " + + " retake(s)";
}
else {
document.getElementById("text").value = document.getElementById("text").value + "You still failed after " + retake + " retake(s)";
}
}
</script>

<body>
<div style="text-align:center">
<h2>Student Test taking simulation</h2>
<p> <input type="button" value="Take the Test" onclick="TakeTest()"> </p>
<p> <textarea id="text" rows="60" cols="25">READY TO GO!</textarea> </p>
</div>
</body>
</html>

Philip M
12-14-2010, 10:20 AM
Have you tried usig your error console/Firebug? It would have indicated:-

document.getElementById("text").value = document.getElementById("text").value + "Your retake grade: " + grade;
}
while (retake <= 3 && grade != passGrade)

There is no function randomInt();

"99.9 percent of lawyers give the rest a bad name." - Unknown

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum