• LOGIN
  • No products in the cart.

Lesson 14: Events – Part 2 [Instructor] PRO

Review the concept of algorithm andwrite the first program

Lesson 14: Events Part 2

 

Review

 

Take a moment to review Events with your class.

Here are some questions that you can ask in review:

Who can tell me what an Event is?

Event An action that causes something to happen.

What did we do last time?

What do you wish we had had a chance to do?

Did you think of any questions after the lesson that you want to ask?

What was your favorite part of the last lesson?

 

Class Discussion: Create buttons

 

Take a Moment to Display the shapes below for all of your class to see. You may project the Image below or use the chalkboard/whiteboard to draw the shapes.

 

 

Have a volunteer to touch any shape. If the volunteer touched the circle, the class claps one time. If they touched the rhombus, the class taps the table. If they touched the square, the class stomps their feet.

Ask a new volunteer to think of three new commands that are safe and appropriate, and have the class perform the actions when they touch the different buttons. You can repeat this 2 or 3 times to entertain and excite the class.

 

Class Discussion: pencilcode.net – Events Part 2

 

Open the Events file from the last class. If students don’t have their own accounts, you can have them log into your account and use your file or you can have them quickly recreate it.

 

 

We are going to program some buttons.

Add the following code illustrating the use of the buttons, the block for buttons is under the section Control.

 

 

Full Text code for the buttons

 

speed (100)

#Event: The code will run when something occurs

#Event: press the “up arrow” key

#Reaction: turtle moves up 10 steps

keydown ‘Up’, ->

fd 10

#Event: press the “down arrow” key

#Reaction: turtle moves down 10 steps

keydown ‘Down’, ->

bk 10

#Event: press the “left arrow” key

#Reaction: turtle turn left and moves 10 steps

keydown ‘Left’, ->

lt(90)

fd 10

rt(90)

#Event: press the “left arrow” key

#Reaction: turtle turn left and moves 10 steps

keydown ‘Right’, ->

rt(90)

fd 10

lt(90)

#Event: press the button grow

#Action: turtle grow 2 times

button ‘Grow’, ->

grow 2

#Event: press the button shrink

#Action: turtle size is reduced half size

button ‘Shrink’, ->

grow 0.5

#Event: press the button pen

#Action: pen is set with color and thickness

button ‘Pen’, ->

pen purple, 10

#Event: press the button “pen off”

#Action: pen is off

button ‘Pen off’, ->

pu()

Now the students can draw anything by using the events keydown and button.

 

 

Challenge: Create Multiple Buttons with different uses.

 

For this challenge, you will add some code to your file from last week to add 4 buttons to your project that can perform different actions.

Assignment Objectives:

Create at least four buttons that perform the following actions:

1. A button that will make a box.

2. A that will make a dot.

3. A button that will hide the turtle.

4. A button that will show the turtle.

-Extra: Any button you can come up with!

 

Text code for the 4 buttons.

 

button ‘Grow’, ->

grow 3

button ‘Shrink’, ->

grow 0.5

button ‘Pen’, ->

pen purple, 10

button ‘Pen off’, ->

pu()

button ‘Box’, ->

box yellow, 50

button ‘Dot’, ->

dot green, 50

button ‘Hide’, ->

hide()

button ‘Show’, ->

show()

 

Full code below:

 

 

Wrap Up

 

What is an event?

Why do we need to be able to handle events in a program?

Can we write any type of code for an event?


ABOUT

Kids Love Code is supported by education and technology experts out of the Harvard and Stanford Graduate School of Education and the MIT Media Lab. With these proven, project-based courses, Kids Love Code offers the ideal synthesis of online learning and STEAM education.
Read More

Premier Coding Platform

Premier Coding Platform Available in
15 Countries

Subscribe From

top
Copyright © 2016-2024 Code Rev Kids, Inc. All Rights Reserved. Code Rev Kids, Inc. and kidslovecode.com are not official Minecraft® products. They are not approved by, or associated with Mojang®. NOT AN OFFICIAL MINECRAFT PRODUCT.  NOT APPROVED BY OR ASSOCIATED WITH MOJANG.