Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Build a Random Number Guessing Game

Gilang Ilhami
Gilang Ilhami
12,045 Points

Is it just my code or something is wrong with WorkSpace?

I am unable to open the javascript script for the random guessing numbers game

Either it is my code or it's Workspace being a little buggy.

var randomNumber = Math.floor(Math.random() + 6) + 1;
var guess = prompt("Guess a number between 1 and 6.");
if ( parseInt(guess) === randomNumber ) {
  document.write('<p>Yep that is true!</p>');
} else {
  document.write('<p>Sorry, the number was ' + randomNumber '</p>');
}

2 Answers

Grzegorz Lenkiewicz
Grzegorz Lenkiewicz
5,022 Points

Missing '+' at last line. Should be: document.write('<p>Sorry, the number was ' + randomNumber + '</p>'); And on first line should be * not + : var randomNumber = Math.floor(Math.random() * 6) + 1;

Tommer Haugland
PLUS
Tommer Haugland
Courses Plus Student 4,423 Points

Also, you should multiply Math.random instead of adding to it. like this:

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