Continued 2 Consider this ex xp ression: = JohnsHeight HectorsHeight Goodheart-Willcox Publisher Can this expression s be evaluated as true or false, or is there not enough information? In order to evaluate t this expression, the values of th he variables JohnsHeight and HectorsHeight must be known. . These values are not known at th hi s point, so there is not enough information. 3 Consider this ex xp ression: = JohnsHeight HectorsHeight set to JohnsHeight 58 set to HectorsHeight 62 Goodheart-Willcox Publisher Can this expression s be evaluated as true or false, or is there not enough information? The values of the h variables JohnsHeight and Hecto or sHeight are known, so the expression can be evaluated. d The expression is false because e 58 is less than, not equal to, 62. 4 Consider this ex xp ression: set to roll pick random to 1 6 roll = 5 Goodheart-Willcox Publisher Can this expression s be evaluated as true or false e, or is there not enough information? In order to evalu ua te this expression, the values of o the variable roll must be known. While this value has been set, it is not reported, so there is not enough information. If the random number e is 5, the expression is false. If the h random number is 5, the expression is true. 5 Write an express si on to determine if the variable n nu mber is less than or equal to 6. Assemble the co od e in the Scripts area. This code requires use of the or operator block to create a Boolean n expression that tests for two conditions. n Click the assembled code block to have Scratch evaluate the expression and report o if it is true or false. Try It! You make many y decisions every day, even if you are not aware of it. Think about the school day. Some of t th e most basic decisions you make k are when to arrive, when to change classes, and when to go home. Write a Boolean expression s to test if it is time to go home. Write another Boolean a expression to test if school is in n session. Copyright Goodheart-Willcox Co., Inc. Chapter 5 Decisions 107
Previous Page Next Page