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 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help middle aged (45) newbie

    hi all, fairly new to pc`s(18 month`s) started to wonder how all the scripting works (God knows why?) bought Dummies JavaScript guide but cant make this work any idea`s thanking you in anticipation Neil


    <HTML>
    <HEAD>
    <TITLE>
    </TITLE>


    <SCRIPT LANGUAGE = "JavaScript">

    var userImput;

    var userName;

    var upperLimit = 20;

    userInput = window.prompt('Please enter a number in the range 0 to ' <= upperLimit, '');

    userNumber = parseFloat (userInput);

    while ( (userNumber <= 1 || (userNumber >= upperLimit ));

    {
    userInput = window.prompt('Please re-enter - number should be in range 0 to <= upperLimit,'');

    }
    document.write('<BR>' + Your chosen number was ' + yourNumber');

    </SCRIPT>
    </HEAD>
    <BODY>
    </BODY>
    </HTML>

  • #2
    New Coder
    Join Date
    May 2007
    Location
    SF, CA
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    You had several variable names wrong. Also you need to make sure your strings have quotes at the beginning and end. You didn't parse the float inside the while loop. There was a semicolon in your while loop condition. You had some unmatched parentheses in the while loop condition too.

    Also if you are using Firefox I would recommend using the Javascript Console in the Tools menu. It'll help track down a lot of these problems.

    Code:
    <HTML>
    <HEAD>
    <TITLE>
    </TITLE>
    
    <SCRIPT LANGUAGE = "JavaScript">
    var userInput;
    var userName;
    var userNumber;
    var upperLimit = 20;
    
    userInput = window.prompt('Please enter a number in the range 0 to <= upperLimit', '');
    userNumber = parseFloat (userInput);
    
    while ( (userNumber <= 1) || (userNumber >= upperLimit ))
    {
    userInput = window.prompt('Please re-enter - number should be in range 0 to <= upperLimit','');
    userNumber = parseFloat (userInput);
    }
    
    document.write('<BR>' + 'Your chosen number was ' + userNumber); 
    
    </SCRIPT>
    
    </HEAD>
    <BODY>
    
    </BODY>
    </HTML>
    semper fi...

    gary

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,173
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    javbits beat me to it!

    Why parseFloat()? Surely you are asking for an integer number, so if the user enters (say) 12.3 you want to return 12.

    Note that that accuracy is vital - userImput is not the same as userInput, and remember that JavaScript is case sensitive. Also unmatched quotes will cause the script to fail.
    Last edited by Philip M; 06-08-2007 at 07:43 PM.

  • #4
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by javabits View Post
    You had several variable names wrong. Also you need to make sure your strings have quotes at the beginning and end. You didn't parse the float inside the while loop. There was a semicolon in your while loop condition. You had some unmatched parentheses in the while loop condition too.

    Also if you are using Firefox I would recommend using the Javascript Console in the Tools menu. It'll help track down a lot of these problems.

    Code:
    <HTML>
    <HEAD>
    <TITLE>
    </TITLE>
    
    <SCRIPT LANGUAGE = "JavaScript">
    var userInput;
    var userName;
    var userNumber;
    var upperLimit = 20;
    
    userInput = window.prompt('Please enter a number in the range 0 to <= upperLimit', '');
    userNumber = parseFloat (userInput);
    
    while ( (userNumber <= 1) || (userNumber >= upperLimit ))
    {
    userInput = window.prompt('Please re-enter - number should be in range 0 to <= upperLimit','');
    userNumber = parseFloat (userInput);
    }
    
    document.write('<BR>' + 'Your chosen number was ' + userNumber); 
    
    </SCRIPT>
    
    </HEAD>
    <BODY>
    
    </BODY>
    </HTML>
    semper fi...

    gary
    hi Gary thank you for taking the time and trouble to respond to my problem, i seem to learn best by sort of idiot fashion dont what i`m following at the start but by following the idiot cards it normally sinks in, i know it sounds cheeky but would it be possible for you to either underline or if you would be so kind as to correct the mistakes i have made then i will have a working example to practice on i.e. change bits to see how it works or not in my case. Best regards Neil

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by neilbigh101 View Post
    hi Gary thank you for taking the time and trouble to respond to my problem, i seem to learn best by sort of idiot fashion dont what i`m following at the start but by following the idiot cards it normally sinks in, i know it sounds cheeky but would it be possible for you to either underline or if you would be so kind as to correct the mistakes i have made then i will have a working example to practice on i.e. change bits to see how it works or not in my case. Best regards Neil
    Can you not just compare the updated code with your old code?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Can you not just compare the updated code with your old code?
    hi Aerospace didnt have any old code just tried to dive in and put all the seperate bit`s together know it sounds daft but that way eventually the penny does seem to drop, empahsis on eventually, any further hwlp would be hugely appreciated thank you, Neil

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,173
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Quote Originally Posted by neilbigh101 View Post
    hi Aerospace didnt have any old code just tried to dive in and put all the seperate bit`s together know it sounds daft but that way eventually the penny does seem to drop, empahsis on eventually, any further hwlp would be hugely appreciated thank you, Neil
    He means compare the code kindly provided by javabits with the code you posted originally.

  • #8
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, just like they told me in school "must pay more attention" thank you all very much, it`s much appreciated best regards Neil

  • #9
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers guy`s it works great, you make it look so easy?


  •  

    Posting Permissions

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