Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Working With Numbers The Random Challenge

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);

2 Answers

Shadab Khan
Shadab Khan
5,470 Points

Hi 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 :)

Hey, 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;

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 :)