Hello and welcome to our community! Is this your first visit?
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
    Apr 2013
    Thanked 0 Times in 0 Posts

    Need help with a pretty basic function

    I'm coding an IF game, and am trying to do the following:

    1) set a variable to a user-input value via prompt()
    2) check to see that the variable is a number in between 2 specific values
    3) if not, display a message to the user and re-prompt for the variable

    My thought was that declaring the variable globally and creating a function to check and see if the necessary conditions were met via while loops was the way to go, but I'm running into some problems. Any help would be greatly appreciated!

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Thanked 64 Times in 64 Posts
    homework again?

    i guess school-like aproach would be something like that:
    //declare variables
    //set flag for loop
        //prompt for input
        if(condition1 && condition1 && condition3 ....){
            flag = false;
    //display output
    that's not working code, but should give you an idea how to do it
    Last edited by patryk; 04-14-2013 at 08:07 PM.

    "Real Programmers can write assembly code in any language" - Larry Wall

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,528 Times in 2,506 Posts
    prompts are obsolete. Use DOM methods to obtain input data from and display messages to your users.

    See forum rule #1.5. We will not do your homework for you.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    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.


    Posting Permissions

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