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

Simple solution

Just thought I shared my solution to the problem. Only three lines of code, and it works well. Any feedback is welcome.

var userInput = parseInt(prompt('Type in any number'));

var randomNumber = Math.floor(Math.random() * userInput) + 1;

alert(randomNumber + ' is the number between 1 and ' + userInput);

Please don't provide solutions to code challenges. It makes others not want to try to solve the challenge on their own and nobody can become a good programmer by copying-and-pasting others code.

Thank you for understanding :smile:

~Alex

Thanks Alex for the comment. It's not my intention to post solution to a code challenge; the solution is actually for an assignment on one of the Random Number videos on the JavaScript track. I thought I linked it to the original video; apparently I don't know how to do so, I'm still new to Treehouse though. Perhaps you could show me how, or redirect me to the FAQ page on how to do so. :)

1 Answer

Steven Parker
Steven Parker
230,037 Points

I'm not sure which kind of "challenge" you were working on.

Since you didn't provide a link to the course page, I don't know if this is the kind of "challenge" that you must complete on your own to finish the course, or the kind that's more like an "assignment" where the following video shows an example solution. I expect Alexander is assuming it's the former, or he recognizes it as such. If that's the case, I'd agree it might be better not to post it.

But if it's the latter, it might be good if you've come up with a solution that's significantly more compact and/or elegant than the one shown in the video. But to be able to see the difference, you need to include that link to the original.

Hey Steven,

It's the latter part. There is an assignment on the Random Number video where the following video shows one of the solution. I'm still new to Treehouse though, so I don't know how to link the original video to the question I posted.

Steven Parker
Steven Parker
230,037 Points

It's in the Markdown Cheatsheet pop-up, below "Add an Answer" :arrow_heading_down: You'll want to learn how to format code also.

Thanks Steven. That was absolutely helpful! :)