function question - Beginner

Discussion in 'JavaScript' started by askscript, Nov 7, 2008.

  1. #1
    This is the code i have written to add a number by 1 when key in any number:

    the problem is this part:
    When i key in 5, it gives me 51, rather than 6. How should i code it properly for getting it to add up when a value is keyed in at the prompt.
     
    askscript, Nov 7, 2008 IP
  2. askscript

    askscript Member

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    i have found a way to solve it.

    The prompt that you enter will gives you the text value and not integer value, that is why you cannot use it for calculation. You got to change it to an integer value using parseInt()

     
    askscript, Nov 7, 2008 IP