Hey all,
New to the course and coding in general. Just a little bit confused about how this exactly works.
I understand the math that our code is doing, but what’s throwing me off is is how it’s defining our new standard for “guess” each time. At the top we’ve set “guess = 500” , but what in the code is allowing guess to change without conflicting with the original value of 500?
Another instance that is confusing me is, if we’ve established that “min = 1” and “guess = 500”, how does “min = guess” work? Isn’t that also saying 500 = 1?
Here’s how i’ve tried to work it out in my head:
On our first “if” statement for out UpArrow input where we have :
min = guess;
guess = (max + min) / 2;
I understand that is saying that if they press UP ARROW, our maximum remains 1000. And the next guess will be 875, and so on.
However, where I get lost is when we go from up to down.
max = guess
guess = (max + min) / 2;
The math here is that our new max is 750 and our minimum is now 500, giving it the next guess of 625. My question is, where in the code is it retaining the value of 500 for our minimum in this instance? How does the program know that our minimum is going to be 500? From the last input?
Just confused as to how the program is defining what it’s next minimum/maximum is going to be.