Teachers resources

Bevezetés

This is a continuation of the lesson 'VARIABLES WITH A COUNTER'. While 'VARIABLES WITH A COUNTER' focused on variables that stored numbers, here we will store text or strings in our variables. Strings are alphanumeric characters but we do not use them to do math. Instead we mostly use these to display words. Also, storing words in our variables helps to make things more readable sometimes.

Variables change a lot like our emotions do. This lesson asks us to change string variables. We will do this to try and make our baby brother happy. Read on to learn more about the connected to theme to this lesson but remember the focus is string variables and how to manipulate them in the micro:bit.

Our micro:bit course lessons are tailored to apply knowledge obtained from the Code.org CS Fundamentals. Before students begin these Course Lessons, we encourage students to first complete all CS Fundamentals as a prerequisite. Students should be familiar with variables from Code.org CS Fundamentals.

Students and teachers are highly encouraged to first complete the prerequisites in the resources section above.

Variables Challenges Assessment

4 = All three challenges were accomplished
3 = Two challenges were accomplished
2 = One challenge was accomplished
1 = Some challenges were tried but unsuccessful

Independant Practice Assessment

Create Your Own micro:bit Emotions

4 = Is able to rename variables in a meaningful way, load new values in these variables, put the two words together, and display output successfully
3 = 3 of the 4 listed above was accomplished.
2 = 2 of the 4 listed above was accomplished.
1 = 1 of the 4 listed above was accomplished.

Tips on Making Student Presentations Great

It is easiest to use a document camera to demo the student micro:bit programs so that students simply bring their micro:bits to the document camera when presenting. If a document camera is not available, you can have students share their program. Load programs on devices for display by publishing and sharing the URL for the script.

Activity

What you'll need

1 - micro:bit

1 - USB cable

1 - AAA battery pack (optional)

2 - AAA batteries (optional)

Documentation

basic.forever(() => {})

forever

Keep running part of a program in the background.

for(let i = 0; i < 5; ++i) {
basic.showNumber(i)
}

for

Run part of the program the number of times you say.

basic.showString("Hello!")

showString

Show a string on the LED screen

basic.showNumber(0)

showNumber

Show a number on the LED screen

let item = 0
item = 0

setItem

Use an equals sign to make a variable store the number or string you say.

function doSomething() {
basic.showString("Hello!")
}
doSomething()

function

A function lets you create a portion of code that you can reuse in your program.

Imagine you have a baby brother. Every morning, his mood is different. You are babysitting him and you try to deal with his emotions. You are not always successful at calming him but you try. For each mood he presents, you need to give him something. Then you hope it makes him happy but it doesn't always work.

In our program we will show this with string variables. An example of output might be:

Sad + Toy = Happy

Here our brother woke up sad. Then we gave him a toy. Later, he was happy.

We start our program in the forever loop. A variable called 'Morning_Mood' is set to Sad. For this first example, baby brother wakes up sad.

Next, a variable called 'What_to_give' is set to Toy. You try to give your brother a toy because he is sad. Finally, a variable called 'Result' is set to Happy. Giving your brother a toy makes him happy!

The call to the function 'How_Does_Baby_Brother_Feel_Now' displays our string variables. The variables will scroll across the screen.

Follow the link to the starter code. There are extra blocks at the bottom to help you get started

NOTE: The unused blocks at the bottom of the code are meant to be used in the challenges. Also, there is a big function called 'How_Does_Baby_Brother_Feel_Now'. It is not necessary to cover or understand this function. It is only there to help show our output in a more meaningful way. Should you wish to explore it, do so. Otherwise you can ignore it.

Challenge 2

This time it is Night time. Instead of giving your brother something, he wants to do an activity. Rename the two variables(Morning_Mood, What_to_give). You should rename them to something meaningful. Our situation has changed and so the variable need new names to show this. Then change the values of the three variables again to create a new situation at night for baby brother. Your story should make sense.

It appears from this example that the boy does not like to play with a ball. To get full credit, I would probably need to explain why because it seems strange that a young child does not like to play ball.

Challenge 3

Delete 'call function How_Does_Baby_Brother_Feel_Now' in the forever loop. Use the code block with show string join to show your output instead. Join can put our string variables together for us instead of using that big function.

Note: The students variables will be different at this point so the code will be a bit different probably. The important thing is the outcome.

Independent Practice

Put two words together to make a bigger word. This is called a compound word. Use the 'How_Does_Baby_Brother_Feel_Now' function, join, or some other methods to combine two text variables. Try to rename the variables that will store your two words to something meaningful.

Example - Some examples of words you might make would be (play + ground = playground) or (tree + house = treehouse). The variable names themselves might be word1 and word2.

Note: The output does not need to be a real compound word. Make up your own word if you can like 'headfork'. Then have fun telling everyone about the meaning of your new word or why it was made.