JavaScript JavaScript Basics Creating Reusable Code with Functions Random Number Challenge

Nelson J
Nelson J
5,408 Points

Feedback: Generate a random number challenge

var lower = parseInt(prompt("enter first number"));
var upper = parseInt(prompt("Enter second number"));

function randomNum(lower, upper) {
  console.log("random number is " + Math.floor(Math.random() * (upper - lower + 1)) + lower); 

}


randomNum(lower, upper);

Also, can you add in if I need parseInt. I'm confused on that a little.

1 Answer

Steven Parker
Steven Parker
170,448 Points

You have used "parseInt" correctly. Since "prompt" returns a string, the "parseInt" converts that into a number, which is what your "randNum" function expects as arguments.

Good job! :+1:

Steven Parker
Steven Parker
170,448 Points

Nelson J — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!