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 trialjohn larson
16,594 Pointsthrow new error() shows this is the console. "ReferenceError: error is not defined"
function RNG(upper, lower) {
if (isNaN(upper) || isNaN(lower)) {
throw new error ('please enter only numbers: ie; 1, 2, 3...');
}
var RN =
Math.floor(Math.random() * (upper - lower + 1)) + lower;
return RN;
}
var RN = RNG(10, "five");
console.log(RN)
//document.getElementById("print").innerHTML = RN;
1 Answer
Kevin Goudswaard
11,061 Pointsfunction rng(upper, lower) {
if (isNaN(upper) || isNaN(lower)) {
throw new Error("please enter only numbers: ie; 1, 2, 3...");
}
var myNumber = Math.floor(Math.random() * (upper - lower + 1)) + lower;
return myNumber;
}
console.log(rng(10, "five"));
So here is your amended code. You had a syntax error with your throw statement. Those rules can be picky. Your code was very close, yet, uncompleted. It looks like you could have benefited from taking some time to debug a bit. Also another thing I noticed is that you have variables with names that start with a capital letter. I changed that as that is not proper syntax. Lastly, you did not need to declare that last global variable. (var RN = RNG(10, "five") instead, just wrap your input in the console.log function. Hope this helps! Let me know if you need anything else.
Kev
john larson
16,594 PointsThanks Kevin, that's a lot of great input!
john larson
16,594 Pointsjohn larson
16,594 PointsI've tried it error() and error ()