• LOGIN
  • No products in the cart.

Lesson 4: My First Program [Instructor] PRO

Review the concept of algorithm and write the first program

Lesson 4

My First Program

Review the concept of an Algorithm.

An algorithm is a list of steps that you can follow to finish a task.

Activity:

Break the class up into teams.

Have each team come up with several steps that they can think of to complete one task

Gather teams back together into one big group and have one team share their steps, without letting anyone know what the activity was that they had chosen.

Allow the rest of the class to try to guess what activity the algorithm is for.

What is a Program?

Program – An algorithm that has been coded into something that can be run by a machine.

Programming – The art of creating a program.

Activity

Write an algorithm to draw a crescent moon in the sky

Suppose you have a blue square, a blue circle, and white circle, what is the algorithm to draw a crescent moon in the sky.

Let them write an algorithm in groups

Ask volunteers for the steps, write the steps on the board:

1. Draw a big blue square

2. Draw a white circle inside the blue square

3. Draw a blue circle on top of a portion of the white circle

Step By Step

We are going to create our first program in pencilcode.net

1. Login to http://www.pencilcode.net

2. Make a new file: myfirstprogram

3. Add the coding blocks in pencilcode.net one by one showing the results and talking about, about the purpose of each coding line.

box(blue, 1000);

dot(white, 500);

fd(250);

dot(blue, 500);

Comment in Programming

A comment is a description of some code.

Comments in CoffeeScript starts with #

# Comments are used to document your code so it is easier for humans to understand. You should include a comment at the start of each task to explain what the task does. It is also a good idea to comment any complex blocks of code so you, or another programmer, can more easily maintain or modify the code in the future.

This is an Example of a comment in CoffeeScript:

# the dot code simply creates a dot.

This is an Example of a comment in JavaScript:

// the dot code simply creates a dot.

Comments in JavaScript starts with //

Let’s add comments to our program to document it.

When the program is running and the symbol (#, //) is found, the computer ignores that coding line.

Here is the code in JavaScript with comments:

You can copy the code in blue and paste in pencilcode.net

// box is a function in pencilcode to draw a square

// computer is expecting the color and size of the box

box(blue, 1000);

// dot is a built in function in pencilcode to draw a circle

// computer is expecting the color and size of the dot

dot(white, 500);

// fd is a function in pencilcode to move the turtle forward

// computer is expecting the distance that the character will move

fd(100);

dot(blue, 500);

Challenge of the day

Modify the program to rotate the half moon and add other objects in the space.

NOTICE: Line 9 was inserted

// box is a function in pencilcode to draw a square

// computer is expecting the color and size of the box

box(blue, 1000);

// dot is a built in function in pencilcode to draw a circle

// computer is expecting the color and size of the dot

dot(white, 500);

// rt is a function in pencilcode to turn right

// computer is expecting the angles that the character will turn

rt(90)

// fd is a function in pencilcode to move the turtle forward

// computer is expecting the distance that the character will move

fd(100);

dot(blue, 500);

Challenge Part 2

Have students change the color for both the box block and dot block. Then have the students rotate the half moon the other way.

// box is a function in pencilcode to draw a square

// computer is expecting the color and size of the box

box(blue, 1000);

// dot is a built in function in pencilcode to draw a circle

// computer is expecting the color and size of the dot

dot(white, 500);

// lt is a function in pencilcode to turn left

// computer is expecting the angles that the character will turn

lt(90)

// fd is a function in pencilcode to move the turtle forward

// computer is expecting the distance that the character will move

fd(100);

dot(blue, 500);

Wrap Up

What should you write first program or algorithm?

What is the purpose of the comments?

How you start a comment

What happens when the computer finds #, //?

Last Updated:7/25/2019


Attachments12

SEE ALL Add a note
YOU
Add your Comment
Copyright © 2016-2018 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.
ok

great

×
Top
error: Content is protected !!