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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help with onload and var prompt

    Basically I just want my onload function to appear before the prompt for my var. As it goes the prompt appears before the onload. Any help is appreciated. Here is the source:

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title>Lab 6 CST8209 420 Grades</title>
    <meta charset="utf-8">
    <script type="text/javascript">
    
    function welcome()
    {
    alert ("This site will help you convert you're course average from a percentage to a letter grade.");
    }
    
    var grade = parseFloat (prompt ("Please enter you're course average in percentage:"));
    
    if (grade >= 90)
    {
    alert ("A+");
    }
    
    else if ((grade <=89) && (grade >=85))
    {
    alert ("A");
    }
    
    else if ((grade <=84) && (grade >=80))
    {
    alert ("A-");
    }
    
    else if ((grade <=79) && (grade >=77))
    {
    alert ("B+");
    }
    
    else if((grade <=76) && (grade >=73))
    {
    alert ("B");
    }
    
    else if((grade<=72) && (grade >=70))
    {
    alert("B-");
    }
    
    else if ((grade<=69) && (grade>=67))
    {
    alert ("C+");
    }
    
    else if ((grade<=66) && (grade>=63))
    {
    alert ("C");
    }
    
    else if ((grade<=62) && (grade>=60))
    {
    alert ("C-");
    }
    
    else if ((grade<=59) && (grade>=57))
    {
    alert ("D+");
    }
    
    else if ((grade<=56) && (grade>=53))
    {
    alert ("D");
    }
    
    else if ((grade<=52) && (grade>=50))
    {
    alert ("D-");
    }
    
    else if (grade<=49)
    {
    alert ("F");
    }
    </script>
    </head>
    <body onload="welcome()">
    </body>
    </html>
    Last edited by VIPStephan; 10-12-2013 at 08:32 AM. Reason: added code BB tags

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    function welcome()
    {
    alert ("This site will help you convert you're course average from a percentage to a letter grade.");
    }

    <body onload="welcome()">


    Delete the lines in red. Or wrap the rest of your script in another function called after welcome(). The reason why the welcome() appears after the prompt is that it is called onload, that is after all the other page content has been loaded.

    prompts and alerts are regarded as obsolete and should not be used except for testing purposes. I do understand that you are only learning, but it is better to learn good coding practices than bad ones.

    If you do use a prompt you should prevent it from displaying "undefined".
    What if the user types "Mickey Mouse" in response to the prompt? Or 84.5?

    It is recommended that you place the opening brace following the function, if, else, for, while, do, switch, and try statements on the same line and not on the following line. Apart from that every Javascript statement should be followed by a semi-colon (;). It is quite possible to disregard this advice, but if you do one day it will rise up and bite you in the undercarriage.

    These days it is considered best practice in most situations to place scripts right in front of the </body> tag rather than in the <head>.

    you're course average
    Have a look at the difference between your (belonging to you) and you're (contraction of you are). That mistake could result in an employer weeding out your job application at the outset.
    Last edited by Philip M; 10-10-2013 at 08:19 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    Phidler (10-12-2013)

  • #3
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks brother I do appreciate the time you put into replying. This is my first year learning I'm in college.

    Thank you for you're patience.

    Phil

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Phidler View Post
    This is my first year learning I'm in college.
    How many years were you in college, then, before you learned that you are indeed there?

    [Sorry, but I couldn't help myself. Hope you are also taking English class(es).]
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    How many years were you in college, then, before you learned that you are indeed there?

    [Sorry, but I couldn't help myself. Hope you are also taking English class(es).]
    Wow what a dick you are.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,472
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Quote Originally Posted by Phidler View Post
    Wow what a dick you are.
    You just insulted one of the most helpful and knowledgeable members on this forum just because he made a joke about the way you worded something.

    Presumably you don't need any more help with your "early history of JavaScript" class.
    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.

  • #7
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    You just insulted one of the most helpful and knowledgeable members on this forum just because he made a joke about the way you worded something.

    Presumably you don't need any more help with your "early history of JavaScript" class.
    Not matter how smart or bright he is, he was being disrespectful. I was asking for help and his little comment was uncalled for, I don't think I deserved it. I'm here to learn, not to be ridiculed. I did not find his joke funny and his intention was clearly not to me make me laugh. I do not know him well enough to tell whether his comment had racist intentions to it or not but it seemed to be in the nature.

    Judging people because they are not part of the same culture or speak the same language I believe is absolutely intolerable.

    English is my second language and to be honest this forum is for programming, I did not ask for help with my grammar.

    Phil

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Phidler View Post
    Thank you for you're patience.

    Phil
    I think he was trying to draw attention to your failure to take any account of my advice to study the important difference between your and you're.

    But felgall is right - you are unlikely to get much more help in this forum if you have that chippy attitude. And people who see racism in everything are simply contemptible. How could we possibly tell that you are, er, ethnically different? You certainly know enough English to be vulgar.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,480
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Iím sorry, Phidler, but even as a neutral moderator I am kind of on the other peoplesí side here. OldPedantís comment was a purely ironic hint regarding your statement which is accidentally funny because you missed a comma or period in the important place that changes the meaning of the statement tremendously. Itís a mystery to me how you can see racist intentions in such a comment but if you canít even laugh at yourself for such a harmless comment then you should really work on your attitude. Obviously you had a few negative experiences regarding your origins in the past but nobody here knows where you are from or what cultural background you have so itís not appropriate to flip out like that.

    Now, itís on you to get back on topic. If you are here to learn something about programming then talk about programming and not your personal issues.

  • #10
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    Iím sorry, Phidler, but even as a neutral moderator I am kind of on the other peoplesí side here. OldPedantís comment was a purely ironic hint regarding your statement which is accidentally funny because you missed a comma or period in the important place that changes the meaning of the statement tremendously. Itís a mystery to me how you can see racist intentions in such a comment but if you canít even laugh at yourself for such a harmless comment then you should really work on your attitude. Obviously you had a few negative experiences regarding your origins in the past but nobody here knows where you are from or what cultural background you have so itís not appropriate to flip out like that.

    Now, itís on you to get back on topic. If you are here to learn something about programming then talk about programming and not your personal issues.
    Alright, considering everyone here seems to be against me than maybe I was wrong to insult Old Pendant like that so:

    Old Pendant I apologize. And I hope you forgive me.

    And yes I want to focus on programming, I want to learn and I want to be really good at it.

    I know you cannot tell if someone is of ethnic background online or not, and you're right, I can see how people of the same culture can tease and laugh at each-other because of obvious and silly mistakes, it can be comical.

    But know that I struggle to speak English and I make an effort to speak it and write it properly, so when people "hope I'm taking English classes" it offends me, because when I do these silly mistakes I'm actually making an effort, not because I wasn't being careful or focused.

    If you were face to face with someone who clearly had difficulty speaking the language, would you correct that person every time they make a mistake and ask them if they were taking English classes?

    In saying that though, I see now where Old Pendant was coming from, I just hope you guys see when I'm coming from too.

    I hope you all forgive me and forget this ever happened.

    I'm not a bad person, I'm young and inexperienced, I admit when I'm wrong.

    Apologies.

    Phil

  • #11
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    I think he was trying to draw attention to your failure to take any account of my advice to study the important difference between your and you're.

    But felgall is right - you are unlikely to get much more help in this forum if you have that chippy attitude. And people who see racism in everything are simply contemptible. How could we possibly tell that you are, er, ethnically different? You certainly know enough English to be vulgar.
    And I do appreciate you advising me about the grammar mistake because it would look unprofessional and ultimately finding work and delivering a quality product is the idea. Difference is, you were not making fun of me, you were trying to help me.

    Phil


  •  

    Posting Permissions

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