Beginner Coding with Blocks
Chapter
>
Level

Math and Text Operations
Counting with Code

Did you know you can add (+), subtract (-), multiply (*) and divide (/) while coding? Well you can! And in this chapter we're going to teach you how, along with cool ways you can use this feature and how to apply it to what you've learned.

Let's start off by counting all the animals in the stable using the speak block then adding up all their quantities together using math blocks.

Guide

Objective

Determine how many animals there are in each stable and add them up to complete the level.

In this stable you will find cows, goats and pigs, determine how many of each animal are located in each pen. First create variables where you can store the number of animals that are in each pen using the set block.

Use the set block to create variables named cows, goats, and pigs, and set each to the number of animals you count in each pen.

Walk towards the X mark in front of each pen and use the speak block to call out the variable holding the number value for each pen. Use the speak block and connect the variable block (like cows) to it.

Once you've completed this for all three pens, head for the X mark in front of the desk and use the speak block once again but this time adding all three variables together using a math block. Use the math block with the + operator to add cows + goats + pigs, then connect that to the speak block. Now, using basic math operators, you can add up the number of animals in the stable.

Code book