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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Percentage marks to grade

    Hi,

    Kindly assist me with the following.

    The code should produce letter grades for #s range from 0-100.
    Also, alert() should be used in the event of the # not being between 0-100 or 999. I'm trying to accomplish this using the do...while loop.

    The offending line: } if(grade >= 70 && < 80) {
    Syntax error.

    Code:
    <!DOCTYPE html>
    <html>
    
    <head>
    <script>
    do {
    var grade = prompt("Enter test grade\n" +
    		   "Or enter 999 to Quit", 999);
    grade = parseInt(grade);
    
    if(grade >= 0 && grade <= 100) {
    	alert("Letter"); }
    else if(grade !=999) {
    	alert("Numbers range 0 through 100\n" +
    	      "Or enter 999 to quit"); }
    }
    
    while(grade != 999);
    		if(grade < 60) {
    		alert("F");
    	} if(grade >= 60 && grade < 70) {
    		alert("D");
    	} if(grade >= 70 && < 80) {
    		alert("C");
    	} if(grade >= 80 && grade < 90) {
    		alert("B");
    	} if(grade >= 90 && grade =< 100) {
    		alert("A");
    	}
    </script>
    </head>
    
    <body>
    <section>
    	<h1>This is displayed after the JavaScript is executed.</h1>
    </section>
    </body>
    </html>
    Thanks in advance!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Is this for a JavaScript for Netscape 4 course?

    If not you should be aware that prompt() and alert() no longer serve any purpose in JavaScript. You should use forms for input and output directly into the page instead. Those calls were used for debugging from when Netscape 4 died up until Firefox got a built in debugger but now even that purpose (where browsers displayed extra checkboxes in alerts and prompts for turning off either those dialogs or even JavaScript) are no longer needed.

    Also since the death of Netscape 4 all JavaScript now goes just before the </body> tag - with the only exceptions being scripts that have to run before the page starts to render - I know of only two such scripts - one that adds a class to the HTML tag to change what the page shows if JavaScript is enabled (as a complete replacement for the <noscript> tag) and the other where you want to redirect and not display the page at all when certain conditions apply (for example a frame breaker script that redirects to the page itself if the page is currently inside a frame).

    Also parseInt() is for converting from base 2 through 9 or 11 through 36 to base 10. It isn't for converting strings to numbers - the Number() function serves that purpose.


    As for the syntax error - you have the comparison < 80 but there's nothing to the left of the <


    If you use http://jslint.com/ (with Assume a Browser checked) then you will get a complete list of all the errors and potential errors in your code before you even try to run it.


    Also with the antiquated 20th Century JavaScript code you have there there is no DOM or JSON code there at all so why did you pick that sub-forum to post the question in?
    Last edited by felgall; 01-09-2014 at 05:22 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for answering, felgall!

    It's just a simple assigned task.

    Anyway I worked it before.
    I moved the block below while replacing 'alert...' and changed <=100 to <101.

    I was unsure of the exact area within the JavaScript forum.


  •  

    Posting Permissions

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