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

Tijl Declerck
Tijl Declerck
1,211 Points

Why doesn't it show in my web page?

So I've had this problem quite often. I do the exercise but then it doesn't show on the web page. For example:

random.js file

var userNumber = prompt("Pick a number");
var adjusted = parseInt(userNumber);
var randomNumber = (Math.floor(Math.random()*adjusted)+1;

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>JavaScript Basics</title>
 </head>
<body>
  <div class="container">
  <h1>Random Number Generator</h1>
  <script src="random.js"></script> 
  </div>

</body>
</html>

Moderator edited: markdown was added to the question to properly render the code. Please see the Markdown Cheatsheet link at the bottom of the "Add an Answer" section for tips on how to post code to the Community.

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Tijl! You won't see anything with the current code that you have as you've not yet told it to write anything to the document. You've set up your variables etc and it is running the code. But there's no code that actually writes them to the page.

Take a look around 2:44 of this video

Hope this helps! :sparkles:

Tijl Declerck
Tijl Declerck
1,211 Points

It's still not solved. I typed it like they show in the example but still nothing, so damn frustrating.

here's the new thing I tried:

var userNumber = prompt("Pick a number");
var adjusted = parseInt(userNumber);
var randomNumber = Math.floor(Math.random()*adjusted+1;
var message = "<p>" + randomNumber + " is a number between 1 and " + adjusted + ". </p>";                                

document.write(message);
Doegena Fennich
Doegena Fennich
8,974 Points

Tijl Declerck, you forgot to add a parenthese after adjusted.

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