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

Val Ki
Val Ki
1,997 Points

trying to figure out why my prompt isn't popping up

Hi everyone, I trying to complete the challenge along with the teacher video and for some reason, my prompt isn't popping up when I add preview my work. Please help!

var input = prompt("Please type a number"); var topNumber = parseInt(input); var randomNumber = Math.floor(Math.random() * topNumber) + 1; var message = "<p>" + randomNumber + " is a number between 1 and " + topNumber + ".</p>; document.write(message);

1 Answer

Hi there!

By 'not popping up' you mean the prompt dialog doesn't show up or the input you typed doesn't add to the page?

I tested your code and the prompt dialog does show up. Anyway, there's one mistake I've noticed. You forgot to add a closing quote on the </p> tag. Your code has it as "</p> instead of "</p>". Changing that should make it work.

See the working code below.

var input = prompt("Please type a number");
var topNumber = parseInt(input); 
var randomNumber = Math.floor(Math.random() * topNumber) + 1; 
var message = "<p>" + randomNumber + " is a number between 1 and " + topNumber + ".</p>"; 
document.write(message);

I hope it helped!