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 trialKhashayar Mirbabaie Ghane
Full Stack JavaScript Techdegree Graduate 27,891 PointsMy Solution hope it helps.
// Collect input from a user
// Convert the input to a number
const usernumber = parseInt(prompt('please enter your max range number so we give you a random one'));
// Use Math.random() and the user's number to generate a random number
let randomnum = Math.floor(Math.random() * usernumber) + 1;
// Create a message displaying the random number
const main = document.querySelector('main');
if(usernumber){
main.innerHTML = `<h1>your random number is : ${randomnum}</h1>`;
} else {
alert('you need to provide a number,try again');
}