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) Working With Numbers The Random Challenge

Sharing my code before watching the answer video.

So, this is what I came up with. It seems to be working OK, but I didn't test the second one enough to make it sure that it is working 100% properly.

  /* First Challenge
   var maxNumber = prompt("Please, choose a number.");
   var maxNumberInt = parseInt(maxNumber);
   var finalNumber = Math.floor(Math.random() * maxNumberInt) +1;
   alert(finalNumber);
   */


   // Second Challenge
   var minNumber = parseInt(prompt("Please choose the minimum value for your dice roll."));
   var maxNumber = parseInt(prompt("Please choose the maximum number for your dice roll."));
   var diceRoll = Math.floor(Math.random() * ( maxNumber - minNumber + 1 ) + minNumber;
   alert(diceRoll);

   /* Test 1
   Min = 10 Max = 100
   min - 0 * ( 100 - 10 + 1) + 10 = 10
   max - .9999 * ( 100 - 10 + 1) + 10 = 100
   True */

   /* Test 2
   Min = 37 Max = 578
   min - 0 * ( 578 - 37 + 1 ) + 37 = 37
   max - 0 * (578 - 37 + 1 ) + 37 = 578
   true */

1 Answer

I got an "Uncaught SyntaxError: Unexpected token " of course I started looking for Bilbo Baggins.... :)

Then I scrupled the your code. It is missing one thing. It seems there is no closing bracket for this line

 var diceRoll = Math.floor(Math.random() * ( maxNumber - minNumber + 1 ) + minNumber;

This works

 var diceRoll = Math.floor(Math.random() * ( maxNumber - minNumber + 1 ) + minNumber);

I know it was real easy to forget. But we have to watch out for Baggins's, my precious!

Good Luck