Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Atul R
3,446 PointsWhy is it not working this way?
function alertRandom(){
var randomNumber = Math.floor( Math.random() * 6 ) + 1;
return randomNumber;
};
alertRandom();
alertRandom();
alertRandom();
alertRandom();
alertRandom();
/* Is it necessary to add "alert(randomNumber)" command
on line 3 and if yes what does this command convey? */

Nathan Crum
15,183 Pointsfunction alertRandom(){
//You have stored your random number in the variable "randomNumber"
var randomNumber = Math.floor( Math.random() * 6 ) + 1;
/*
* Using "return" will display the random number in your browsers javascript console
* but not on the webpage or in a pop-up box as we have done in previous excercises
*/
return randomNumber;
/*
* Use the alert() function to display the random number in a popup. Now when you
* call your alertRandom() function it will in turn call the alert() function to display
* your number.
*/
alert(randomNumber);
};
alertRandom();
alertRandom();
alertRandom();
alertRandom();
alertRandom();
If you have found my answers helpful please give a +1

Martinus Lukas
Courses Plus Student 3,023 Pointsbecause you just put return inside the function, to use the function with return just call it like this ::
<script>
alert(alertRandom);
</script>
1 Answer

Sergio Niño
Full Stack JavaScript Techdegree Student 22,975 PointsHi, Atul R the error is because the semicolon at the end of the closing curly braces. use it, just when you're using the other way to create a function called: function expression
I hope this helps clear it up. :)
john larson
16,594 Pointsjohn larson
16,594 Points