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
Sandeep Singh
6,083 Pointsjavascript 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
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 PointsYou 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.
Manish Giri
16,266 PointsThis line is incomplete - var ramdomNumber = Math.floor(Math.random * 6) + 1;
Math.random is a function, it needs () to be invoked.
Sandeep Singh
6,083 Pointsstill 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>');
}
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 PointsThis 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>");
}
Sandeep Singh
6,083 Pointsstill 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>');
}
Sandeep Singh
6,083 PointsSandeep Singh
6,083 Pointsgot it! silly me. thank you luc!
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 PointsLuc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 PointsAnytime :)