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) 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;