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

JavaScript JavaScript Functions Arrow Functions Testing for Number Arguments

khaled elfaham
khaled elfaham
3,779 Points

how can I can collect two numbers from the user that will be used in a function?

function results(number1, number2) {

if( number1 <= number2) {
return Math.floor(Math.random() * (number2 - number1 + 1)) + number1; } else if(number2 <= number1){ return Math.floor(Math.random() * (number1 - number2 + 1)) + number2; } }

1 Answer

Steven Parker
Steven Parker
231,236 Points

One easy way to get input is with the "prompt" function. It puts out a message, waits for an answer, and then returns that answer: For example:

var answer = prompt("Please type a number: ");

Note the the result is always a string. If you intend to do math with it, convert it into a number first.