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 Solution

Konrad Dziekonski
Konrad Dziekonski
7,798 Points

my solutnion to challenge no1

hello!

my solution is a bit different but seems to be working, could you tell me if it is acceptable?

function randomArea(lower, upper) {
  var lower = Math.floor(Math.random() * lower - 1 ) + 1;
  var upper = Math.floor(Math.random() * upper) + 1;
  return upper - lower;
}

thanks!

2 Answers

Steven Parker
Steven Parker
231,268 Points

Perhaps your testing could be a bit more thorough. For example, try generating a number between 50 and 60 (*"randomArea(50, 60)").

And here's a hint: Math.random() should be called only once in the function.

Konrad Dziekonski
Konrad Dziekonski
7,798 Points

You are right, thank you.

Tell me... because in the first video Dave said that programming is like writing a story using programming language and synthax. But so far its more like solving mathematical logics riddles. Is it going to be like that but harder? Learning languages has always been fairly easy for me, but math or physics wasn't. Do I have a chance to be a good prgrammer? Are there any skills and knowledge outside pure programming field that would help me become good programmer?

Thanks

Steven Parker
Steven Parker
231,268 Points

Certainly some programming tasks will involve math, but not all do. And even those that require math are often satisfied by well-known and published formulas that you can look up.