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 trialPhilipp Kushnir
1,751 PointsWhat is wrong?
var numberOne = prompt("Whatis the firs number"); var numberTwo = prompt("What is the second number"); var result = Method.floor(Method.random()* numberOne) + numberTwo; alert(result);
2 Answers
Shadab Khan
5,470 PointsHi Phillip,
Use need to replace 'Method' by 'Math' as below and that should get rid of the error for you. floor() and random() are math functions.
var numberOne = prompt("Whatis the firs number");
var numberTwo = prompt("What is the second number");
var result = Math.floor(Math.random() * numberOne) + numberTwo;
alert(result);
Also you can use Google Chrome's console (Ctrl + Shift + I) on windows to debug JavaScript snippets like these
Hope that helps, all the best :)
Daniel Jordanov
816 PointsYou also have to parse "numberOne" and "numberTwo" into integers. The "prompt" method returns a string and you need an integer. That's my solution to the problem:
var input = parseInt(prompt("Type a number: ")); // asks the user for a number, parses it into an int and stores it in the variable named input
var secondInput = parseInt(prompt("Type another number: ")); // asks the user for a second number, parses it into an int and stores it in a variable named secondInput
var randomNumber = Math.floor(Math.random() * input) + secondInput; // generates a random number between the first input and the second number and rounds it down
alert("Your random lucky number is: " + randomNumber); // opens a diagonal box displaying the random number
Hope I helped :)
Philipp Kushnir
1,751 PointsPhilipp Kushnir
1,751 PointsHey, thank you for a reply. I think I didn't get the idea. Since the task is to generate a random number between variables numberOne and numberTwo;