The dialog the question is asked in.
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:

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) seconds
    change [points v] by (1)
else
    say [Wrong!] for (2) seconds
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 depending on the input
when gf clicked
ask [Do you like books?] and wait
if <(answer)=[yes]> then
    say [Nice! I like them too!] for (2) seconds
end
if <(answer)=[no]> then
    say [That’s not a problem!] for (2) seconds
end

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.