-
Title:
25c s Different Behavior Based On Certain Condition- Smoothie Quiz
-
Description:
-
I love smoothies.
-
Let's look some code from
the SmoothieActivity.
-
First, we create an integer variable
called numberOfSmoothiesTillPrize and
-
we initialize that to a value of ten.
-
Then we have an if-else statement.
-
It spans from line two to line seven.
-
If the numberOfSmoothiesTillPrize
is greater than nine,
-
then do the code within the opening and
closing braces here.
-
If this statement is not true, then do
the code in this else block right here.
-
Since the numberOfSmoothiesTillPrize
has a value of ten, and
-
ten is greater than nine,
then we fall into the if case here.
-
We print out a log message that says,
-
'Congratulations, you
get a free smoothie!".
-
Then we update
the numberOfSmoothiesTillPrize variable
-
to be this new value.
-
This evaluates to ten minus ten,
-
which is zero, so we essentially
update this to have zero smoothies.
-
That makes sense, because once you've
reached ten smoothies, and you get
-
a free one, your count goes back to zero
and and you have to buy ten more again.
-
So this has a value of zero,
let's continue.
-
Well, we've reached then end
of this if block of code,
-
and we skip over the else lock
because we only do one or the other.
-
And so we immediately go down here.
-
In this last code statement, we add
a log message that says, you currently
-
have blank out of 10 smoothies
needed for your next free smoothie.
-
This blank here is actually a variable
called numberOfSmoothiesTillPrize.
-
And this currently has a value of zero,
because we updated it here.
-
So this message would say,
you currently have zero out or
-
ten smoothies until your next free one.
-
Therefore, the answer is C.
-
By stepping through the code,
we got the message, Congratulations,
-
you get a free smoothie!
-
And we also saw the message,
-
You currently have 0 out of 10
smoothies until your next one.
-
Option A, is incorrect, because we
definitely did get a free smoothie.
-
Option B, is incorrect because
we updated the number of
-
smoothies count back to zero.
-
Nice job trying to recode that
you didn't understand before and
-
trying to pick the answer.
-
Continue on to learn
exactly what is going on.