Trstan Velez3,693 Points
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!
Jeff MudayTreehouse Moderator 26,165 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!!