Wilshire Posted August 6, 2006 Share Posted August 6, 2006 I'm trying to teach myself javascript, and going through some totorials I saw a counting example where it would count from 0 to 9 and display it. It was a little too easy, so I made my own version which would ask you where to start counting, where to end, and what to count by. For some reason, it combines everything into a string instead of adding the numbers. Code is below, any help would be appreciated. <html><head></head><body><script type="text/javascript">var start=prompt("Start at:");var end=prompt("End at:");var increment=prompt("Count by:");while (start<=end){document.write(start+"<br />");start+=increment;}</script></body></html> Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 6, 2006 Share Posted August 6, 2006 You could set the variables to the datatype you want Like this way: var start=Number(prompt("Start at:"));This is because the datatype the prompt function returns, is always a string. If you want it to act as a digit, number, use this function Link to comment Share on other sites More sharing options...
Wilshire Posted August 6, 2006 Author Share Posted August 6, 2006 Thanks, that did it. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 6, 2006 Share Posted August 6, 2006 You're welcome Anytime :)Oh, and remember, if the user puts in a value that is not a number, it will still try to see it as a number. So if you entered "g4jtu5", it probably would use "45" instead Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now