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 Basics (Retired) Creating Reusable Code with Functions Random Number Challenge, Part II

KAMRAN IMRANLI
KAMRAN IMRANLI
4,107 Points

Help with my code

Hello everyone! Can someone check my code and tell me what is wrong?

function getRandomNumber( lower, upper ) { if (isNaN(lower)==true || isNaN(upper)==true){ alert(Error('Sorry! You have not entered a number.')); } else { return Math.floor(Math.random() * (upper - lower + 1)) + lower; } } document.write(<p> getRandomNumber('nine', 24) </p>); document.write( <p>getRandomNumber( 1, 100 )</p> ); document.write( <p>getRandomNumber( 200, 'five hundred'</p> ) ); document.write( <p>getRandomNumber( 1000, 20000 ) </p>); document.write( <p>getRandomNumber( 50, 100 )</p> );

1 Answer

Steven Parker
Steven Parker
231,275 Points

When posting code, use Markdown formatting to preserve the code's appearance.

But even as-is, it looks like there is HTML mixed in with the JavaScript, which would cause syntax errors. Remove the HTML tags and the code will probably be OK.

KAMRAN IMRANLI
KAMRAN IMRANLI
4,107 Points

Steven Parker I will take Markdown formatting into consideration for the next time. Thanks for the link! And regarding my code, I have seen on tutorials here at TreeHouse, where teachers themselves use HTML tags in Javascript. I thought it is possible.

Steven Parker
Steven Parker
231,275 Points

Take another look at those examples, you'll find that any HTML tags are part of strings being used to create page content, and not just in the code by themselves.