Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIsaac Calvo
8,882 Pointshow to remove/convert all non-numbers a user might input into the prompt box for ex: $ , . letters etc?
code so far: // create a rng // collect user input // print a random number 1 >= user's provided number
anything entered into the prompt box that is NOT 0 - 9 breaks the program.
var item = prompt('What would you like to sell?'); var userNumber = parseInt(prompt('How much do you want for the ' + item + ' ?')); var offerPrice = parseInt(Math.ceil(userNumber) * Math.random() + 1); alert('Would you take $' + offerPrice + ' for your ' + item + ' ?');
Isaac Calvo
8,882 PointsIsaac Calvo
8,882 Points""... Use the string's .replace method with a regex of \D, which is a shorthand character class that matches all non-digits:
myString = myString.replace(/\D/g,''); ...""
found the above at stack will this work also for the prompt box? Also is this way above what I'm learning? I have never seen .replace or the \D