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

What's wrong with my code?

Whenever i try to run my code it displays error: unexpected token

Here is my code snapshot: https://w.trhou.se/tj5h4n6ymc

2 Answers

I just forked your project and I checked Javascript Console, everything seems fine. Some times your browser wont pop up an alert.

Instead of alert(getRandomNumber(5,10)); try document.write(getRandomNumber(5,10)); that will probably allow you to see if your syntax is correct. If you do feel like you are messing up always trust the Javascript Console as it will help you in all your syntax errors, or errors in general.

Erwin Meesters
Erwin Meesters
15,088 Points

You can't set a default argument value the way you did:

function getRandomNumber(min_number, max_number, include_max_number = true){
  // function stuff
}

You can change your function to:

function getRandomNumber(min_number, max_number, include_max_number){
  // function stuff
}

You can call your function like:

alert(getRandomNumber(5,10, true)); // with max_number included
alert(getRandomNumber(5,10, false)); // without max_number included