Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Need suggestions on >.o this code

    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 Thank you for your time~ ^_^
    Code:
    <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."
    		   {
    		   var retake, passGrade, grade;
    		   retake = 0;
    		   grade = randomInt(1, 100);
    		   passGrade = 70;
    		   if (grade >= passGrade) {
            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>
    	</head>
    	
    	<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>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,314
    Thanks
    203
    Thanked 2,565 Times in 2,543 Posts
    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

  • Users who have thanked Philip M for this post:

    seulki (12-14-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •