Seems like a dumb question, but where is the text set to “True” and “False”?
Event handlers can be used to handle, and verify, user input, user actions, and browser actions:
Things that should be done every time a page loads
Things that should be done when the page is closed
Action that should be performed when a user clicks a button
Content that should be verified when a user inputs data
Thanks for the reply. I understand about event handlers. What I don’t see are writing the text “true” false" in the code:
text(keyDown(“up”), 200, 200);
Doesn’t the last line refer to the x,y coordinate? I am sure that my students will ask this and I won’t have an answer.
The “true”/“false” text comes from the
keyDown() block. That block returns either true or false, depending on whether the key is pressed down. The
text block prints that value to the screen.
text(keyDown("up"), 200, 200);
For example, if the up arrow is pressed down, the above line of code evaluates
keyDown("up") to true, then prints “true” to the screen at (200, 200), the (x,y) coordinates that you mentioned in your post.
Normally we use true/false (Booleans) in conditionals, such as using an
if statement to move a character up the screen only when
keyDown() is returning.
Got it. Thank you for the very clear explanation. I suspected as much but wanted to make sure before I told my students. I am not sure when they are asked to predict what happens with the code that they will answer “true” or “false.”