Results 1 to 2 of 2

Thread: Why won't this work?

  1. #1
    Join Date
    Oct 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why won't this work?

    Code:
    var sentence = "|zero|one|two|three|four|five|six|seven|eight|nin e|"
    var numbers = sentence.split("|");
    var input = parseInt(window.prompt("Enter a number"));
    
    for(i=0;i<numbers.length;i++)
    {
    if(i==input)
    {
    document.write(numbers[i+1]);
    }
    else
    {
    i++;
    }
    }
    How can I get this so that if the user type in 1, it outputs one
    2 = two
    3= three

    so on...

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Code:
    <script type="text/javascript">
    
    var sentence = "zero|one|two|three|four|five|six|seven|eight|nine"
    var numbers = sentence.split("|");
    var input = parseInt(window.prompt("Enter a number"));
    
    for(i=0;i<numbers.length;i++)
    {
    if(i == input)
    {
    document.write(numbers[i]);
    break;
    }
    }
    </script>
    Changed your sourcode a bit. This will do what you said.

Bookmarks

Posting Permissions

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