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
Dylan George
1,293 PointsCreate a variable named "chance" and assign a random number between 0 and 20 to it using the Math.random() method.
Create a variable named "chance" and assign a random number between 0 and 20 to it using the Math.random() method.
I have entered the following but it returning the error: "Oops! It looks like Task 1 is no longer passing."
var diameter = 5.75,
a = 17,
b = 42,
c = 1337,
ageIfILiveToYear2100 = (new Date(2100, 0, 1) - new Date(1995, 5, 16, 7, 20)) / (1000 * 60 * 60 * 24 * 365.242);
var circumference = diameter * Math.PI;
var chance = Math.random()*20)+1);
```
6 Answers
eirikvaa
18,015 PointsYou have some unneeded parentheses in your last statement.
var chance = Math.random()*20+1;
Elijah Collins
19,457 PointsI used
var chance = Math.random()*20;
Armando Flores
10,059 PointsThat seemed to work for me too, anything else was messing up problem #1.
Syed Hassan
Courses Plus Student 776 Pointsvar chance = Math.random()*20+1; I could not understand where the + 1 come from?
Syed Hassan
Courses Plus Student 776 PointsI agree with Elijah. Shouldn't it be var chance = Math.random() * 20 ; ?
christopher couret
10,297 Pointsthis answer worked for me var chance = Math.random() * 20 ; thank you
Jeremy Lindstrom
6,646 PointsYou add the +1, because it would never go to 20, since it starts at 0.
Dylan George
1,293 PointsDylan George
1,293 Pointsbeauty, thanks Eirik.
Paul Miller
1,277 PointsPaul Miller
1,277 PointsWhy doesn't it accept the code, var chance = Math.random(20);
Works fine in the console.