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!
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
What 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);
Shadab Khan5,470 Points
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);
Hope that helps, all the best :)
You 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 :)