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) Working With Numbers The Random Challenge Solution

I left out parseInt, but this code still seems to work????

Math.floor(Math.random()) + 1; var userNumber = prompt('pick a number '); var randomNumber = Math.floor(Math.random() * userNumber) + 1; alert( randomNumber + ' is between 1 and ' + userNumber );

1 Answer

When using binary operators, javascript will use type coercion to try and make your code work and not give an error, javascript is very forgiving.

Run these in the console and see what happens

'25' + 5
25 * '5'
'25' - 5

so I guess the moral is "do it right" cause maybe sometimes will let you slide...sometimes not. ty