<< Chapter < Page | Chapter >> Page > |
The block labeled sqrt will deliver about a dozen different representations of numeric values, depending on what is selected from thepull-down list. This includes the square root, trigonometric functions, absolute value, etc.
Finally, the block labeled round will round a decimal number to the nearest whole number.
Image 4 shows the result of dragging the top two green blocks from the left panel and dropping them into the white boxes in the bottomtwo orange variable blocks in the center panel of Image 3 .
If you compare Image 4 with Image 2 , you will see that Image 4 is close to what we need but we aren't quite there yet. In order to causethe bottom two blocks in the center panel in Image 4 to match the bottom two blocks in Image 2 , we need to do the following:
That's the solution. The upper left portion of your Stage area should now look similar to Image 5 . Note however that you may need to use the mouse to arrange the four variables and the button to get your Stage arrangedlike Image 5 .
Once you reach this point, you can click the green flag to initialize all four variables to zero.
Then you can move the sliders back and forth to manually set the values for the variables named LeftOperand and RightOperand .
Then when you click the button at the bottom of Image 5 , the variable named Sum will display the sum of the values of the top two variables, and the variable named Diff will display the value of LeftOperand minus the value of RightOperand .
A copy of this program has been posted online for your review (see Resources for the URL) . If you don't find the program using that URL, search the Scratch site for the usernamed dbal.
I encourage you to use the information provided above to write this program. Experiment with the code, making changes, and observing the results of yourchanges. Make certain that you can explain why your changes behave as they do.
Just for fun, move the button a little to the right and cause it to say Ouch for about five seconds each time you click it as shown in Image 6 . Hint: See the purple button labeled Looks in Image 3 .
I also encourage you to write the program described below.
Write a Scratch program named Arithmetic02 that produces the output shown in Image 7 when the user adjusts the sliders to the values shown and clicks the button. Make the word Ouch! appear and then go away after about five seconds.
Notification Switch
Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?