If the letter is wrong, draw a body part
Right away we can turn that into one of the Five Concepts in the table below. But what is the conditional testing? What does it mean to say "the letter is wrong"? It means that the first letter of the word is not the letter that was guessed, and the second letter of the word is not the letter that was guessed, and the third letter of the word... What does that look like to you? (Hint: look for one of the Five Concepts).
That was easy. Here's a harder problem. How is the computer going to remember the "and"ness between the interations of your loop? How does the computer remember anything? (Hint: look for one of the Five Concepts). That's not the hard part, because everything comes down to one or more of those five concepts. The hard part is deciding what exactly is this variable going to remember?
When your iteration begins, you have not looked at any of the word to be guessed to see if this letter is there. You -- or rather the computer, but you are getting into the computer's "head" and imagining that you think like a computer, so right now it's you -- don't know anything at all about this letter. Then (inside the iteration) you look at the first (or second or whatever) letter of the word and you ask if this letter is the same. If it is, it is a correct guess and you are out of here. Otherwise you still don't know anything, so you look at the next letter of the word and do the same analysis.
So what happens if you get all the way through the word, and it isn't the last letter either? You are still out of the loop, but what do you know? At every step through the iteration, you know nothing at all about this letter, except that it wasn't any letter of the word you looked at so far. That's what your variable must mean when you start the loop: "nothing so far." You can use a "boolean" variable type, where false means "nothing" and true means "gotit" (so you would name the variable "gotit" because you want the conditional
if gotitto mean exactly what the English means, "if you got it, if you found a match, then do whatever..."
Or you can use an int (integer number) variable to count the number of times the letter matched -- of course it will never get higher than one, because you are already out when you found a match, but you could name the variable "found" because it's zero until you found something, and your conditional test will look like this
if found>0or maybe
if found==0and the English means "if we didn't find any matches..."
Do you see what's going on here? It's important that you use variable names that make sense in your English description of what the program does, because otherwise you (the programmer) will become confused, and your program will do its very best to match your confusion (and it will always succeed, meaning it won't work correctly).
The second half of the conditional, the part that tells the computer what to do if it never found any matching letter, Vivian has it drawing a body part. That's tricky, so let's kick the can down the road, and just count up the errors for now, the number of guesses that didn't match any letter in the word. Do you think you can do all that? Just write the details (the parts we have discussed so far) of Vivian's fourth line in English in the text panel, do the best you can, and then turn the page.
Five Basic Concepts Sequence Iteration Conditional Variables Input/Output
Revised: 2021 June 3