Time for action - label newAmount

We will once again compare the days and count values as a way to determine if we should perform an action. This time, we want to know when to display the value in the newAmount variable:

  1. Select the double sprite from the list of sprites.
  2. Add a second when space key pressed control block to the scripts area.
  3. Add a wait until block to the when space key pressed block.
  4. We want to wait until count = days before we run our code. Add the = block to the wait until block.
  5. From the Variables palette, add the count block to the left side of the equals block and the days block to the right side of the equals block.
  6. From the Looks palette, add the say block to the wait until block.
  7. We want to report the value in the newAmount variable, so drag the newAmount block into the say block.
    Time for action - label newAmount
  8. Run the script. The final value displays in a speech bubble on the screen.
Time for action - label newAmount

What just happened?

If we started with one dog bone and doubled it every day for seven days, we would have ended up with 64 dog bones. Our Scratch program told us so. Our dog would love us.

When the count equaled the days, we told our sprite to say whatever amount was in the newAmount variable. Because the newAmount variable constantly changed throughout the program, the only calculated value we cared about was the last one. We knew we had the last calculated value when count < days no longer evaluated to true.

The first scenario to cause count not to be less than days was when count was equal to days, which was the logic we represented in our script.

Pop quiz

  1. The go to block can do all of the following except:
    • Go to the location of another sprite
    • Go to location of the mouse cursor
    • Go to the location of the current sprite
  2. Which of the following effects can you set via the Pen palette:
    • Color
    • Shading
    • Size
    • All of the above

Find the interest earned on a lump sum

We're finally ready to move on to the second piece of our problem. We now know how rapidly a single dollar can grow if we double it each day. For comparison, we're going to assume we have a lump sum of $15,000 that will accrue interest over a single time period, which we'll assume is 30 days.

We'll allow the user to set the interest rate. Instead of graphing this equation, we'll add a wise old sprite to do the math for us and report the total amount for comparison with the double graph.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.89.60