+ Reply to Thread
Results 1 to 3 of 3

Thread: Javascript Check Number Help

  1. #1
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Javascript Check Number Help

    I need some help checking a number and seeing if it is between two numbers and if it is, continue, if not, ask for another number.

    I don't have much to start with, but I do have this


    Code:
    var num = prompt("Enter number to view more information about an album 1-6 Only");
      var num = parseInt(num);
    Last edited by Chris S; 03-05-2009 at 03:15 PM.

    I would love to change the world, but they won't give me the source code

  2. #2
    blobtech is offline x10Hosting Member blobtech is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    16

    Re: Javascript Check Number Help

    This should work...

    Code:
    var num = parseInt(prompt("Enter number to view more information about an album 1-6 Only"));
    while(num < 1 || num > 6)
    {
         num = parseInt(prompt("Enter a valid number between 1 and 6 to view more information about the album"));
    }
    What the code does:
    It first asks for a number, and then keeps repeating to ask while the condition "num is smaller then 1 or bigger then 6" is still true.

  3. #3
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: Javascript Check Number Help

    that's what I was missing...thanks. I kept on trying to do and if else statement...I had a general idea of what I was trying to achieve but wasn't sure how to go about doing it.

    Nothing like going above and beyond. This was kind of for a homework assignment. The original assignment was have a box pop up and ask for a number. when the number is given...display the array corresponding to that number. Well, I wanted to do the check against that. Once again thanks for helping me.

    I would love to change the world, but they won't give me the source code

+ Reply to Thread

Similar Threads

  1. Javascript Help
    By goldy30 in forum Programming Help
    Replies: 5
    Last Post: 12-03-2008, 12:53 PM
  2. validating forms - javascript - help needed
    By goldy300 in forum Programming Help
    Replies: 4
    Last Post: 12-02-2008, 11:43 AM
  3. A question about javascript files
    By rlodge in forum Programming Help
    Replies: 6
    Last Post: 12-19-2007, 11:26 AM
  4. XML and Javascript
    By cuteboytm in forum Graphics & Webdesign
    Replies: 1
    Last Post: 09-21-2007, 10:00 AM
  5. Some nice-simple JavaScript effects !!
    By careerbridge in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 07-13-2006, 08:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers