Sentinel Loop Exercise -
05-14-2011, 10:05 AM
I am stuck on exercise 3 at the end of chapter 4. The exercise is this:
Add a tree to the triple jump while loop world. Make the sentinel to be the tree's height, rather than the number 5., so that the loop will execute when the distance is less than or equal to the tree's height, but stop when the distance passes its height. To do this, you can use the character-level function that returns an object's height.
I added a birch tree to the world. I am keeping the counter. I am changing the while instruction to tell it to keep running as long as long as the distance the whiteRabbit is traveling is less than or equal to the height of birchTree.
I kept the counter and tried these while instructions:
While birchTree height is below whiteRabbit height
While birchTree height is >/= whiteRabbit distance above ground
While whiteRabbit distance to ground is < birchTree height
None of these worked. I then realized that I am missing the character-level function that returns an object's height.
I am not sure if any of those while instructions are correct but I won't know until I get it to report the object's height. I must be overlooking something in the book because I do not know how to get it to report this. Can someone point me in the right direction?
|