Hands-On Example 5.3C Hands-On Example 5.3C Nested IF Statements t In Chapter 4, you learned Scratch can find the nu um ber of items in a list. A similar concept is counting how man ny letters are contained in a user’s s text input. This program determines the number of character rs the user entered for a password d and decides if it is the correct length. Two choices are provided v if the condition is false. 1 Launch Scratch. 2 Delete the cat sprite, p and insert a laptop computer r sprite. You may choose a different sprite. 3 Add the when Green Flag clicked block to the script.i 4 Applying what you y have learned, add code to ask k the user to “Enter a six-character password, ” and wait w for the input. 5 Applying what you y have learned, add code to di is play the password to the user. Use the join block to com mb ine a statement such as “You entered ” with the value of the answer variable. 6 Applying what you y have learned, declare a local variable v named textLength. This variable will hold the number of characters the user enter re d. Uncheck the variable so it will not be displayed on the e stage. 7 Using the set variable a to e value block, write an expression p that assigns the length of the e value stored in a an swer to the textLength variable, as shown. The length of value operator e will find the num mb er of characters entered. when clicked ask Enter a six-character password. and wait say answer . join join You entered set to textLength answer length of Goodheart-Willcox Publisher 8 Add an if then else block to the code stack, and code o the condition as IF the variable textLength is equ ua l to 6. This tests if the user has entered e exactly six characters. 9 In the first section o of the if then else block, add code o to state “Your password is ” joined to the value of the h variable answer. This is the cod de that will be processed if the condition is true. 0 In the second se ec tion of the if then else block, add d another if then else block. This begins a nested section of o code that will be processed if th he main condition is false. - In the nested block, o write an expression that tests s the condition IF the variable textLength is less than 6. Continued Copyright Goodheart-Willcox Co., Inc. 114 Introduction to Computer Science: Coding