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 code not working

my code is not working.. its not showing any messge.

var ramdomNumber = Math.floor(Math.random * 6) + 1; var guess = prompt('Guess the number between 1 to 6');

if( parseInt(guess) === randomNumber){ document.write('<p>you are Right!</p>');

}else {

document.write('<p>Sorry' + randomNumber + 'is the number!' + '</p>');

}

3 Answers

You made a typo my friend. You wrote raMdomnumber and you are adding the var raNdomnumber that doesn't exist. Fix the variable and everything works.

got it! silly me. thank you luc!

Anytime :)

This line is incomplete - var ramdomNumber = Math.floor(Math.random * 6) + 1;

Math.random is a function, it needs () to be invoked.

still not working,

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

var guess = prompt('Guess the number between 1 to 6');

if( parseInt(guess) === randomNumber){ document.write('<p>you are Right!</p>');

}else {

document.write('<p>Sorry' + randomNumber + 'is the number!' + '</p>');

}

This should work. As Manish stated above Math.random is a function.

      var randomNumber = Math.floor(6 * Math.random() ) +1;
      //alert(randomNumber)
      var guess = prompt("Guess the number between 1 - 6");


      if (parseInt(guess) === randomNumber)
      {
        document.write("<p>" + "You are right! " + "</p>");
      }
      else
      {
        document.write("<p>" + "Sorry, " + randomNumber + "Is the number!" + "</p>");
      }

still my code is not working.

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

var guess = prompt('Guess the number between 1 to 6');

if( parseInt(guess) === randomNumber){ document.write('<p>you are Right!</p>');

}else {

document.write('<p>Sorry' + randomNumber + 'is the number!' + '</p>');

}