## ← 25c s Different Behavior Based On Certain Condition- Smoothie Quiz

• 2 Followers
• 40 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=0tGr1V5hy58" data-team="udacity"></div> ``` 13 Languages

Showing Revision 4 created 05/24/2016 by Udacity Robot.

1. I love smoothies.
2. Let's look some code from
the SmoothieActivity.
3. First, we create an integer variable
called numberOfSmoothiesTillPrize and
4. we initialize that to a value of ten.
5. Then we have an if-else statement.
6. It spans from line two to line seven.
7. If the numberOfSmoothiesTillPrize
is greater than nine,
8. then do the code within the opening and
closing braces here.
9. If this statement is not true, then do
the code in this else block right here.
10. Since the numberOfSmoothiesTillPrize
has a value of ten, and
11. ten is greater than nine,
then we fall into the if case here.
12. We print out a log message that says,
13. 'Congratulations, you
get a free smoothie!".
14. Then we update
the numberOfSmoothiesTillPrize variable
15. to be this new value.
16. This evaluates to ten minus ten,
17. which is zero, so we essentially
update this to have zero smoothies.
18. That makes sense, because once you've
reached ten smoothies, and you get
19. a free one, your count goes back to zero
and and you have to buy ten more again.
20. So this has a value of zero,
let's continue.
21. Well, we've reached then end
of this if block of code,
22. and we skip over the else lock
because we only do one or the other.
23. And so we immediately go down here.
24. In this last code statement, we add
a log message that says, you currently
25. have blank out of 10 smoothies
needed for your next free smoothie.
26. This blank here is actually a variable
called numberOfSmoothiesTillPrize.
27. And this currently has a value of zero,
because we updated it here.
28. So this message would say,
you currently have zero out or
29. ten smoothies until your next free one.
30. Therefore, the answer is C.
31. By stepping through the code,
we got the message, Congratulations,
32. you get a free smoothie!
33. And we also saw the message,
34. You currently have 0 out of 10