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 trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Random Number Challenge

Sean Flanagan
Sean Flanagan
33,235 Points

Would appreciate feedback

Hi.

I'd really appreciate some feedback.

http://w.trhou.se/hs95d2ect4

Sean

2 Answers

Nice work Sean, I like how you space, it's nice and clean how I code. The only thing to note, I didn't know if you meant to put the + 1 before the (). Because Math object .random() method returns a random number between 0, up to but not including 1. It could possible return 0 * (upper - lower + 1) . But just talking out loud, if you are getting the results of this equation you want, then it's looks good brother.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Cody. Thanks for your feedback.

What's the difference between my code and Dave's?

Here's another snapshot including Dave's code:

https://w.trhou.se/sdr6no0qbb

Cheers brother

Sean

They return the same items. Dave's code just uses one less line of code since the addition of the lower parameter technically doesn't have to be done on the same line since it is just basic addition. Nice work Sean on adding the '+1' to the (upper- lower) portion to get the most possible numbers in the random range.