How to Code: Tutorial on functions, turning and walking backwards

Alphabets Sounds Video

share us on:

In this lesson, students learn about coding objects and their functions, focusing on how to make a monkey character turn and walk backwards. They explore three methods for turning the monkey—turning right or left, using degrees, and turning towards another object—while also discovering how to make the monkey walk backwards by using negative values in the step function. The lesson encourages hands-on practice and highlights helpful coding tips, making the learning process engaging and fun.

How to Code: Tutorial on Functions, Turning, and Walking Backwards

Hi there! Welcome to our fun coding adventure with Code Monkey! Today, we’re going to learn about something called objects and how we can make them do cool things. We’ll also discover two new ways to make our monkey turn, and even how to make him walk backwards. Ready to dive in? Let’s go!

What Are Objects?

In our coding world, objects are everything you see and can interact with, like bushes, bridges, bananas, and turtles. Some objects can do special actions, like our monkey, who can step and turn. These actions are called functions, and the numbers we add to them are called arguments. For example, when we use the function step(10), the number 10 is the argument.

Turning the Monkey

Now, let’s talk about turning. There are three ways to make an object turn:

1. Turn Right or Left

We already know how to use turnRight or turnLeft. These are simple and direct ways to turn our monkey.

2. Turn Using Degrees

Another way to turn is by using degrees, like turn(45) or turn(-90). But how do we know how many degrees to turn? Here’s a secret: our ruler is also a protractor! When we measure the distance from the monkey to the banana, it shows the angle, like 45, which tells us how much the monkey needs to turn to face the banana. You can use this trick to measure angles from the monkey or the turtle.

3. Turn To Another Object

The third way is using the function turnTo. With turnTo, you don’t need to use right, left, or numbers. This function figures out the direction to turn so the monkey faces another object, like a banana or a bridge. Just use the object’s name, and you’re set!

Walking Backwards

Now, let’s learn how to make the monkey walk backwards. When we want him to go forward, we type step(10). To make him go backwards, we type step(-10). The computer understands -10 as 10 steps in the opposite direction.

Cool Trick!

Here’s a neat trick: if you hover over any object on the stage, its name will appear next to it. If you click on the object, its name will be added to your code editor. This is super helpful if you don’t feel like typing!

Thanks for joining this tutorial! Now it’s your turn to practice turning and walking backwards. Just remember, if you try this in real life, watch out for bananas on the floor. Have fun and good luck!

  1. What new insights did you gain about objects and their functions from the article?
  2. How do you think the concept of using arguments in functions can be applied to other areas of coding or problem-solving?
  3. Reflect on the different methods of turning the monkey. Which method do you find most intuitive and why?
  4. How does the ability to turn using degrees enhance your understanding of angles and directions in coding?
  5. In what ways do you think the turnTo function simplifies the process of directing objects in a coding environment?
  6. What are your thoughts on the concept of walking backwards using negative arguments? How might this be useful in other coding scenarios?
  7. How do you feel about the interactive elements, like hovering over objects to see their names? How does this feature impact your coding experience?
  8. After reading the article, what are you most excited to try out in your own coding practice, and why?
  1. Object Identification Game

    Explore your surroundings and identify objects that could be part of a coding world, like bushes or bridges. Write down what actions these objects might perform if they were in a code, similar to how the monkey can step and turn.

  2. Turn and Walk Challenge

    Create a small obstacle course in your classroom. Use commands like turnRight, turnLeft, and step(10) to navigate through it. Try using degrees to make precise turns and see how accurately you can follow the path.

  3. Angle Measurement Activity

    Use a protractor to measure angles in the classroom. Practice turning by using degrees, just like the monkey does. Try turning to face different objects and see if you can get the angles right!

  4. Backwards Walking Experiment

    In a safe space, practice walking backwards by counting steps. Compare how it feels to walking forwards. Discuss how using negative numbers in coding can change the direction of movement.

  5. Code Your Own Adventure

    Write a short story where you are the monkey. Use coding terms like step and turnTo to describe your journey. Share your adventure with the class and see how creative you can get!

Sure! Here’s a sanitized version of the YouTube transcript:

Hi, welcome back to our Code Monkey tutorials! Today, we will learn about objects and how to use them. We will also learn two new ways to make the monkey turn: how to make him walk backwards and a helpful trick. Ready? Here we go!

What are objects? Objects are everything in the scene we can interact with, like the bush, bridge, banana, and turtle. Some objects have a set of actions they can perform. For example, the monkey can step and turn. These actions are called functions, and the input we add to them is called an argument. For example, in the function `step(10)`, we have the argument `10`.

Now let’s talk about the function `turn`. There are three ways to make an object turn. The first way is to use `turnRight` or `turnLeft`, which we already know. A second way to turn is by using degrees, like `turn(45)` or `turn(-90)`. But how would you know how many degrees to turn? You ask! Well, our ruler is secretly also a protractor. When we measure the distance from the monkey to the banana, it also shows the number `45`, which is the angle the monkey has to turn in order to face the banana. You can use the ruler to measure degrees from the monkey or from the turtle.

The third and final way to turn is by using the function `turnTo`. When using `turnTo`, we don’t need to use `right`, `left`, or a number. The `turnTo` function calculates the direction to turn in order to face another object. All we need is the name of another object, such as `banana` or `bridge`.

Another useful skill you are going to learn in this video is walking backwards. Remember that in order to tell the monkey to go forward, we type `step(10)`. So if we want him to go backwards, we type `step(-10)`. The computer will read `-10` in this context as 10 steps backwards.

Now I want to show you a cool trick! If you hover over any object on the stage, you will see its name appear next to it. If you click on the object, its name will be added to the editor. This can come in handy if you don’t feel like typing right now.

Thank you for watching this tutorial! Now it’s time for you to practice turning and walking backwards. But remember, if you do it in real life, be careful not to step on any bananas. Good luck!

Let me know if you need any further modifications!

CodingThe process of writing instructions for a computer to follow. – Example sentence: In our computer class, we learned the basics of coding by creating a simple game.

ObjectsItems or elements in a program that can hold data and perform actions. – Example sentence: In the game, the characters and the background are all objects that we can control with code.

FunctionsBlocks of code that perform a specific task and can be used whenever needed. – Example sentence: We used functions to make the character jump and run in our game.

TurnTo change direction in a program, often used in controlling movement. – Example sentence: The robot will turn left when it reaches the wall.

DegreesA unit of measurement for angles, often used in programming to control rotation. – Example sentence: We programmed the robot to turn 90 degrees to the right.

MonkeyA playful character often used in coding games to teach programming concepts. – Example sentence: In the coding game, the monkey collects bananas as it moves through the levels.

StepA single movement or action in a sequence of instructions in a program. – Example sentence: Each step in the program moves the character closer to the goal.

BackwardsMoving in the opposite direction from the way one is facing, often used in programming to control movement. – Example sentence: The robot moved backwards to avoid the obstacle.

AngleThe space between two lines that meet at a point, used in programming to control direction. – Example sentence: We adjusted the angle of the cannon to hit the target in the game.

BananaA common item or goal in coding games, often used to teach programming concepts. – Example sentence: The monkey collected a banana each time it solved a puzzle in the game.

All Video Lessons

Login your account

Please login your account to get started.

Don't have an account?

Register your account

Please sign up your account to get started.

Already have an account?