In between two numbers, help


#1

I am on the building rock paper scissors part where you need to have the stuff where if it's in between 0 and .33, .34 and .66, .67 and 1.00. but how do I say in between??? Do I just say <=.33, <=.66, <=1.00, because if I do that, then if it below .33 then it falls under all three categories... Help me out.


#2

Hey @loganbf,

The answer to that question is yes. Why, you say?

I say that that's false. If it's below .33, then it's only below not after. So, yes.

Each falls under only one category, if put in that order for if/else if/else loop, for those loops go from top to bottom. :smiley:


#3

Could you post an example of how you would code this?
This:

<=.33, <=.66, <=1.00

would just be a syntax error if you take this literally but it would be ok if it explains the idea. The thing is that you don't need to bother about this in between stuff anyway as Math.random already limits your results. As it goes from 0 to very close to 1 you already made sure that it is above 0 and below 1 so at most one in between case is needed. And if you use

if(condition1){code1}
else if(condition2){code2}
else{code3}

then only 1 of these is picked. If condition1 is true it's code1 otherwise you go on and check condition2 as well. Meaning to get to condition2 means that condition1 was false already and therefore you don't need the in between here as well. The idea is that you have 3 ranges 0 to 0.33, 0.34 to 0.66 and 0.66 to 1 but you don't need to set up your conditions as in between statements to get this behaviour.