- This article is about the value. For the block, see Answer (block).
The Answer is a value that is the string provided by the user the last time the Ask () and Wait block was used. It is useful for creating quizzes and detecting what the answer was and to make a simple poll on Scratch. This value was first introduced in Scratch 1.4.
Related Blocks
The following blocks can be used in conjunction with this value:
(answer)
— Reports the answerask [] and wait
— Sets the value to something which the user inputs
Example Uses
Some common uses for the answer value:
- Getting a user’s answers on a quiz
when gf clicked ask [What is 2+2?] and wait if <(answer)=[4]> then say [Correct!] for (2) secs change [points v] by (1) else say [Wrong!] for (2) secs end
- Let a user make decisions in choose your own adventure games
ask [Will you enter the castle?] and wait if <(answer)=[yes]> then broadcast (enter castle v) end if <(answer)=[no]> then broadcast (go back v) end
- Asking a user to choose a username
when gf clicked ask [Please type your username.] and wait set [username v] to (answer) say (join [Hello ] (join (username::variables) [!]))
- Giving different responses on different inputs
when gf clicked ask [Do you like books?] and wait if <(answer)=[yes]> then say [Nice! I like them too!] for (2) secs end if <(answer)=[no]> then say [That’s not a problem!] for (2) secs end