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 trialLeo Penaloza
8,426 Points"Any code in the function after the return statement isn't run."
"Any code in the function after the return statement isn't run." What is the purpose on disabling the execution if you purposely added it? Example is below.
function getRandomNumber() { var randomNumber = Math.floor( Math.random() * 6 ) + 1; return randomNumber; alert("Hi"); }
1 Answer
Morgan Welch
24,127 PointsYou will have to alert before the return or after the function call. Most likely after the call. The purpose of a function is reusable code. If there is a return statement then the purpose of that reusable code is to get a value. A return statement "breaks" the function, basically signaling "okay we're done here, got what we needed" and passes whatever needs to be passed wherever it needs to go.