YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

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

Get Embed Code
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
    smoothies until your next one.
  35. Option A, is incorrect, because we
    definitely did get a free smoothie.
  36. Option B, is incorrect because
    we updated the number of
  37. smoothies count back to zero.
  38. Nice job trying to recode that
    you didn't understand before and
  39. trying to pick the answer.
  40. Continue on to learn
    exactly what is going on.