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

Alec Picinich
Alec Picinich
3,470 Points

Can someone tell me why this code won't run correctly?

const lowNumber = prompt("If you had to choose a low number?")
const highNumber = prompt("If you had to choose a high number?")
const intChecker = parseInt(lowNumber, highNumber)

function getRandomNumber(lowNumber, highNumber) {
  return randomNumber = Math.floor(Math.random() * (highNumber - lowNumber + 1)) + lowNumber;
}

if(intChecker == true) {
  alert(`Your random number is ${getRandomNumber}!`);
} else {
  alert("Those aren't numbers you silly goose");
}

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,785 Points

So close Alec. I think your problem is with the parseInt function. The second parameter of parseInt is the base (10 for decimal and 2 for binary etc). A quick and dirty way to fix it would be to have intChecker1 and intChecker2 to test both inputs. Then in your if statement check both conditions with a Logical AND (&&)

You're so close so I don't want to just give you the answer. You can do it! Let me know if you need more help

Update: After looking at this more closely you have a few more issues. You need to parseInt your inputs before passing them to the random function and you don't want to return randomNum =. You just want to return the result of math.floor(...)