AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Contents · Computing

Working with sound and text in Scratch

Lessons 31 · 1 lessons · D.T. Kamaltdinova, D.M. Sayfurov. Informatics and Information Technology, Grade 5 (general editor F.M. Zakirova). “Nashriyot uyi Tasvir”, Tashkent, 2020
31

Working with sound and text

Textbook: pp. 100–102
GoalBuild a simple conversation program in which a sprite asks a question, takes the user’s answer and makes a sound.
New words
ask ... and wait: the sprite asks and waits for the typed answer · so‘ra va kutanswer: the block that holds what the user typed · javobsay: shows a speech bubble · aytif ... then: runs blocks only when a condition is true · agar ... bo‘lsa
Explanation

In Scratch a sprite can talk with the user. For this we use “ask ... and wait” from Sensing: when the program runs, a typing box appears at the bottom of the stage and the user types the answer and presses Enter. The typed reply is held in the “answer” block. The “say” block from Looks shows words in a speech bubble. To combine several pieces of text use the “join” block from Operators: for example “Great choice: ” and the answer join into “Great choice: apple”. For sound the Sound category has “start sound” and “play sound until done”. The “if ... then” block runs its commands only when the condition is true, for example if the answer equals 5 it says “Correct!”. For safety: never type a password, home address or phone number into your project or someone else’s; let sprites ask only harmless questions such as a name or favourite colour.

!Careful!
A sprite must never ask for a password, home address or phone number.
💡 Where will I use this?
In real life

A librarian asks “which book do you need?” and, depending on the answer, sends you to the right shelf. A question, an answer and an action based on the answer are the basis of a dialogue. In a program the “ask and wait” block works like this.

Who uses it

A programmer writes software that talks with the user, a game designer composes a character’s replies, and an author of a help program plans the questions.

Try it today

Ask a friend a question, wait for the answer and react differently according to it; write the chain in your notebook as “question → answer → reaction”.

Worked examples
Startask: favourite fruit?say: “Great choice: ” + answerstart soundEnd
A fruit program: green flag → ask “What is your favourite fruit?” and wait → say (join “Great choice: ” answer) for 2 seconds → start sound.
Startask: 2 + 3 = ?answer = 5yesno“Correct!”“Try again”End
A maths game: ask “What is 2 + 3?” and wait → if answer = 5, say “Correct!”, otherwise say “Try again”.
Class activity

“Chat program”: pairs build a short conversation (2 questions, 2 answers) with a favourite sprite. Another pair tests it and finds mistakes or unclear spots.

Practice
1
Which block takes the user’s reply and in which category is it?
2
How do we join the text “Great choice: ” with the answer?
3
The program asks “What is 7 + 8?”. Which number must “answer” equal in the condition?
4
Why is it unsafe to make a sprite ask for a password or address?
Story of the Week · The Khwarizmi WayQuestions for the Memory TeaClose the week: all of this week’s subjects in one storyRead →