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 trialSam Kautz
Full Stack JavaScript Techdegree Student 3,194 PointsMy code seemed too simple compared to the solution. Am I thinking about this wrong?
Hey, guys. Can you please take a look and see if what I wrote is going to cause some issues? It seemed simple but after reviewing the Solution I feel like my code is over simplified?
var lownumber = prompt('Enter a low number!');
var highnumber = prompt('Enter a high number!');
var randNumber = Math.floor(Math.random() * (highnumber - lownumber +1));
var message = (Math.floor(randNumber));
document.write('A number between ' + lownumber + ' and ' + highnumber + ' is ' + message + '!!!');
2 Answers
Steven Parker
231,275 PointsYou're very close, but it looks like you forgot to add the low number back in when implementing the standard formula. And you should convert the inputs from strings to numbers rather than depending on implicit type coercion.
And you don't need to perform the "floor" operation a second time.
Fix those, and you'll essentially have the classic solution.
Veselin Radosavljevic
3,863 Pointsand he will get a string instead of a number coz var lownumber is a string ..