Count dots on 5 black and white cards (without a loop)

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that asks the user to enter 5 black and white cards representing bits ('B' for black and 'W' for white which are entered one at a time) and displays the total number of dots as the output.

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided:

Input Output
B
W
B
B
W
9
B
B
B
B
B
0
W
W
W
W
W
31

Languages

Scratch

What it should look like

Click on the green flag, enter the inputs provided in the “testing examples” to see the expected output of your program.

Recommended blocks
when green flag clicked

say (total number of dots)
if <(answer) = [W]> then
end

if <(answer) = [W]> then
end

if <(answer) = [W]> then
end

if <(answer) = [W]> then
end

if <(answer) = [W]> then
end
ask [What's your first card (B for black, W for white)?] and wait

ask [What's your second card (B for black, W for white)?] and wait

ask [What's your third card (B for black, W for white)?] and wait

ask [What's your fourth card (B for black, W for white)?] and wait

ask [What's your fifth card (B for black, W for white)?] and wait
set [total number of dots v] to [0]

set [total number of dots v] to ((total number of dots) + (16))

set [total number of dots v] to ((total number of dots) + (8))

set [total number of dots v] to ((total number of dots) + (4))

set [total number of dots v] to ((total number of dots) + (2))

set [total number of dots v] to ((total number of dots) + (1))
Hints
  • Make a variable called “total number of dots” and set it to 0. Add the corresponding number of dots (16 for the first input, 8 for the second input and so on) to the “total number of dots” every time the end user enters ‘W’ as the input. You would need to use 5 if <> then blocks for this challenge.
  • Use the set [] to [0] block to set the value of your new variable. Use the () + () operation under “Operators” to add to the value of your variable.
  • The if <> then block checks if the condition is true and then runs the blocks inside of the if block.

Show Scratch solution

Python
Block-based