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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Bjørn Jakobsen](https://secure.gravatar.com/avatar/452e1b8d64f59a073a2e44d85116439a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Bjørn Jakobsen
Front End Web Development Techdegree Graduate 17,003 PointsMy solution with a second validation to check if the high number is higher than the low number
// Collect input from a user
const lowUserNumber = prompt('Please provide your lowest number.');
const highUserNumber = prompt('Please provide your highest number.');
// Convert the input to a number
const lowNumber = +lowUserNumber;
const highNumber = +highUserNumber;
console.log(lowNumber);
console.log(highNumber);
if(lowNumber && highNumber ){
if ( (highNumber > lowNumber) ) {
// Use Math.random() and the user's number to generate a random number
const randomNumber = Math.floor( Math.random() * (highNumber - lowNumber + 1) ) + lowNumber;
// Create a message displaying the random number
document.querySelector('main').innerHTML = `${randomNumber} is a random number betwwn ${lowUserNumber} and ${highUserNumber}`;
} else {
document.querySelector('main').innerHTML = `The second number has to be higher than the first. Try again.`
}
} else {
document.querySelector('main').innerHTML = `You need to provide two numbers. Try again.`
}
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsWhen posting code, use Markdown formatting to preserve the code's appearance and retain special symbols.
But a nice enhancement to the example program. You'll probably think of many ways to improve the examples in future lessons.
Bjørn Jakobsen
Front End Web Development Techdegree Graduate 17,003 PointsBjørn Jakobsen
Front End Web Development Techdegree Graduate 17,003 PointsThank you! Uppdated the comment with markdown.