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

    user prompts and number input

    hi to all,
    appreciate any help you can give, i want to be able to ask a customer to enter their name (max 8 characters) then a number upto the number of characters they put in if they go over it there prompted to re-enter again, have only been doing this for 2 weeks so have a lot to learn but will keep on trying, have spent 2 days coming up with this:
    (ps any idea were i can get free tutorial, cheapscate i know thanks again Neil)

    <HTML>
    <HEAD>
    <TITLE>
    How to enter characters and number + how many times a letter appears
    </TITLE>

    <SCRIPT LANGUAGE = "JavaScript">

    var userInput;<= 8
    var userValue;<= 8


    userInput = window.promt('Please enter a name with a maximum of 8 characters','');

    document.write('You have entered the following word' + userInput + '<BR>');

    inputValue = window.promt('Please enter a number in the range 0 to 8');

    document.write('The number of times the letter a appears is +userInput + '<BR>')

    </script>
    </body
    <head>

  • #2
    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
    Sounds like a homework assignment. A great many problems, I fear.

    var userInput;<= 8 // you cannot do this. A variable can only be assigned a specific value, e.g. var userInput = 8; Or an expression such as var x = y+6; Note that the semi-colon comes at the end of the statement, not within it.

    userInput = window.promt('Please enter a name with a maximum of 8 characters','');

    prompt. And you just assigned a value to userInput.

    </body // no closing > tag and no <body>
    <head> // you already have a <head> section, but no </head/>


    This is something like what you want, but it does not count the number of letter a.

    <HTML>
    <HEAD>
    <TITLE>How to enter characters and number + how many times a letter appears</TITLE>

    <SCRIPT LANGUAGE = "JavaScript">

    var userInput = window.prompt('Please enter a name with a maximum of 8 characters','');
    while (userInput.length>8) {
    userInput = window.prompt('Maximum of 8 characters, please!','');
    }

    document.write('You have entered the following word:- ' + userInput + '<BR>');
    inputValue = window.prompt('Please enter a number in the range 0 to 8', '');
    theNumber=parseInt(inputValue); // remember that inputValue is a string, change to a number
    while ((theNumber <0) || (theNumber>8)) {
    inputValue = window.prompt('Only within the range 0 to 8, please!');
    }

    document.write('The number of times the letter a appears is ' + theNumber + '<BR>')

    </SCRIPT>

    </HEAD>
    <BODY>
    </HTML>

    As a tip, it is better to give your variables names which immediately make it clear what they relate to.
    userInput could be anything. userName is much clearer.
    Likewise inputValue (could be anything) would be better as userNumber.

    Hope this moves you forward!
    Last edited by Philip M; 06-12-2007 at 07:19 PM.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi Philip, its not home work, well i say not homework i'm hoping to start night classes in September, i got hold of the 2005 sylabus and just thought i'd dive straight in then in September under tuition it might just all come together, can't do me any harm, (he say's getting greyer) and it does facinate me feel like a kid in a sweet shop, you never know sometime in the future may be able to contribute myself, give a little back thank you very much best regard's Neil

  • #4
    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
    Try and get hold of a book called "JavaScript in Easy Steps" by Mike McGrath.
    Published Computer Step www.ineasysteps.com.
    It is an excellent beginner's instruction book. (Third Edition April 2006 is £10.99)

    As I mentioned before, JavaScript is not very forgiving, and accuracy is essential. A spelling mistake, or a misplaced comma, or a missing bracket can (will) stop your script working completely. And don't forget that JavaScript is case sensitive. Hello, hello and heLLo are all different.
    Last edited by Philip M; 06-12-2007 at 07:33 PM.

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you Philip your time and trouble, your obvious experience is definatley much appreciated, i'll try and get the book you suggested , Neil


  •  

    Posting Permissions

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