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 trialSohil Jokhiya
7,033 PointsWhat'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
Ethan Moffat
3,223 PointsI just forked your project and I checked Javascript Console, everything seems fine. Some times your browser wont pop up an alert.
Erwin Meesters
15,088 PointsYou 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
Ethan Moffat
3,223 PointsEthan Moffat
3,223 PointsInstead 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.