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 trialLuke Haddad
6,082 PointsI'm unsure what I'm doing wrong. It's working fine when I preview it until I get to 'math.random()' part
console.log("Begin program");
alert("Welcome! Are you lucky enough?");
var questionOne = prompt("Please enter your first number below.");
var integerOne = parseInt(questionOne);
var questionTwo = prompt("Please enter your second number below.");
var integerTwo = parseInt(questionTwo);
var message = math.random()* (integerTwo - integerOne + 1) + integerOne;
document.write("Here" + "'s" + " your lucky number" + ": " + "message" + ".");
console.log("End program");
4 Answers
Steven Parker
231,275 PointsJavaScript is case-sensitive. You want Math, not math.
Also, if you want to display the random calculation instead of the word "message" itself, you'll need to remove the quotes from around message in your document.write.
And you might want to make use of Math.floor() to use only the integer part of that calculation.
Mateo Buitrago
5,629 Pointsdocument.write("Here" + "'s" + " your lucky number" + ": " + "message" + ".");
You are typing the variable message as a string, no as a variable, delete the quotation marks so it will work as a variable.
document.write("Here" + "'s" + " your lucky number" + ": " + message + ".");
Luke Haddad
6,082 PointsThank you very much! It's no problem now
Ren Dreamur
Python Web Development Techdegree Student 8,587 PointsHere's a rewrite of some of your code that worked for me.
console.log("Begin program"); alert("Welcome! Are you lucky enough?"); var questionOne = prompt("Please enter your first number below."); var integerOne = parseInt(questionOne); var questionTwo = prompt("Please enter your second number below."); var integerTwo = parseInt(questionTwo); var message = Math.random() * (integerTwo - integerOne) + integerOne; var message = parseInt(message); document.write("Here" + "'s" + " your lucky number" + ": " + message + "."); console.log("End program");