Lesson 6 Operators

Operators, Add the traffic lights to the School Day project.

When we talk about operators, we mean anything that add, subtract, multiply or divides. Then anything that tests to see if this value is equals to, which one is bigger than the other or smaller than the other. We have other mathematical operators, also we can join strings together and find the length of a string.

Probably the most important operators are the 'OR' 'AND' 'NOT' operators. The picture can help you understand this. We will use these operators in things like, an IF tests or in a FOR loop. In fact we have seen the green operators in most of the demos in this course.

AND , OR and NOT operators.

This is simple but it can be difficult to understand at first. We will say it and say it again, take your time. Have a look at the pictures below, it is so important to coding to understand how to use our AND,OR and NOT operators.

Comparing our Variables.

We have operators to compare our variables, along with other things. The easiest one to understand is '=', that used in IF and conditional FOR loops. Numbers are the easiest to understand when 3 = 3 this obvious, we can also easily understand 2 < 3 is true and 4 > 5 is not true. Even after years of coding, we will at time have to think what is happening here. As always take your time and understand what is going on.

So strings are a bit more difficult. We need to understand that every letter is given a number to represent it in the computers memory, Ada and Alan have a little note on the ASSCI code, but the numbers 0 to 9 are held in the computers memory as 48 to 57 and the letters A to Z are held in the memory as 65 to 90. The computer will compare two strings from left to right, looking at each character (That is a letter or number) and if the result is the same at the end of the comparison it will be equal. Please look at the picture below.

A tip with Scratch if you mouse over and click the operator sign like = < > in the green blocks it will tell you if the clause is true or false.



ASSCI explained click here.


This section is for our members, you can get details of how to become a member on our ready to go page. The members site is here.





Working with strings.



We have looked at how to work with strings before in lesson 3. Do you remember this code? You may have understood this and if that is the case well done. We will just explain a bit more about it now, as we are talking about operators now. All 3 types of the operators in the bottom picture are used here. In the REPEAT UNTIL block we test on the more than '>' operator. As we never know at the time of writing the code, how long a word the user will enter. We measure that words length, in the variable 'WhatwasSaid'. We could have just measured 'answer' but we felt as you where only just being introduced to variables it was a bit much to take in at that stage, but as you understand more now you can take that step out. We now use the join operator, to join the letter at the position stored in the 'thisnumber' variable. That is increased by 1 on every loop, remember the repeat will finish when this number is more than 'WhatwasSaid'. We are going to look at this code again in our debugging lesson, because there is a logic bug (a mistake) you may have spotted it.



This section is for our members, you can get details of how to become a member on our ready to go page. The members site is here.




The Calculator Demo.

We have put together a calculator in Scratch for you. Its a good way to demonstrate operators. We are using broadcasts and for the first time we have introduced lists. We will have much more on the subject of lists, in the next set of lessons. Alan and Ada will be explaining, how we have put this project together for our members. So its time to say good bye to our non members. We hope we have helped and we would be delighted to welcome you as a new member. If you do join us please be sure you review the first 6 lesson again, there is plenty in the members area you have yet to see.


This section is for our members, you can get details of how to become a member on our ready to go page. The members site is here.




Download the Calculator Project here


The Traffic light project.

The Traffic Light project is available in our members area. This will be a part of the school day project, where getting to school on time is the object of the game, or not if that is how you want to play it. This game develops out of Scratch into JQuery as you become a coder in your own right. We hope you can join us on this journey in our members area.


Down Load the traffic Light Project

This section is for our members, you can get details of how to become a member on our ready to go page. The members site is here.






This section is for our members, you can get details of how to become a member on our ready to go page. The members site is here.



Where Next

So well done. You can call your self a coder now but you really can't just stop now. We have got the next set of lessons coding with scratch, lesson 7 to 12. if you decide to complete these lessons you will cover the following subjects.

Lesson 7 : Inputs and Outputs.

Lesson 8 : Working with Lists.

Lesson 9 : Drawing well designed sprites.

Lesson 10 : Planing an application.

Lesson 11 : Testing.

Lesson 12 : Debugging.