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 Numbers The Math Object Random Number Challenge – Solution

Is it a bad idea to combine two variables like I did here

I was wondering if combining two variables in to one is a good idea or not. Here's what I'm talking about

const randomNumber = Math.floor( Math.random() * ( parseInt(inputHigh) ) ) + 1;

These are the two variables I combined (These are from Guil's variables)

const highNumber = parseInt(highNumber);

const randomNumber = Math.floor( Math.random() * highNumber) + 1 );

Is it bad practice to do this?

P.S I kind of did this on accident, I'm just wondering if it's ok to do it or not. Thank you!

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

The answer is... it depends.

This is a great question to ask.

If you are writing pilot code that only you will use while developing an idea then it's fine. You want to brainstorm. You can always go back and refactor.

But if you are writing production code you would want to break it down further.

In production, you might want to tell a user about errors. So if they input a non-integer you would want to tell them about it and give them an alternate opportunity to correct it. When you have broken it down, then you will have the ability to put additional code to trap the error and deal with it.

Good luck with your Python journey and remember to have fun and experiment!!

Thank you!