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

Luqman Shah
Luqman Shah
3,016 Points

Please review my code

Please review my code before I proceed to the solution video, thank you.

First Method:

function getRn () {
  var randomNumber = Math.floor(Math.random() * (6 - 1 + 1)) + 1; 
  alert(randomNumber);
}
getRn();

Second Method:

function getRn (numberOne, numberTwo) {
  var randomNumber = Math.floor(Math.random() * (6 - 1 + 1)) + 1; 
  return alert(randomNumber + ' is a number between ' + numberOne + ' and ' + numberTwo);
}
getRn(3, 4);
Matthew Long
Matthew Long
28,407 Points

I reviewed your code, but looks like you deleted your post.

3 Answers

Steven Parker
Steven Parker
231,275 Points

Your second method takes 2 arguments, but it does not use them in the formula to control the number being picked. If you pass values that are both higher than 6, what the alert shows will never be true.

It might be helpful to proceed to the next video, and compare your code with the instructor's as a way to evaluate it yourself.

Luqman Shah
Luqman Shah
3,016 Points

I literally failed every challenge in this course............

Steven Parker
Steven Parker
231,275 Points

If you would like help with a specific challenge, start a question from within the challenge using the "get help" button, which should automatically format and attach your code with a link to the challenge to the question.

Luqman Shah
Luqman Shah
3,016 Points

I know that's what I've been doing, and you've helped me with the majority of those challenges, thanks btw! I watch the videos a couple times, I take notes, I follow along in work-space, I ask questions, I pass the quizes and code challenges(the other code challenges, not the workspace code challenges, the workspace code challenges are the ones I always seem to be stuck with), I wonder if this is the case for everybody else, or do people just nail the work space challenges in a breeze.

Steven Parker
Steven Parker
231,275 Points

You might find this episode of The Treehouse Show helpful. It discusses learning styles and blocks, and ways to deal with them.

You shouldn't worry too much about it, because you're not the only one. JavaScript is a challenging language, but you just have to keep at it. Honestly, I've watched some of these JavaScript videos multiple times until the concept sticked and I feel like I have a WHOLE lot more understanding of it now. You should watch the video that Steven suggested if you haven't done so yet. It might help you with your niche in learning the content. Happy coding and best of luck to you!

Nope not just you. I fail these too.