Discuss Scratch

seasnail2024
Scratcher
5 posts

how do I use operators?

I dont really understand operators . I dont know what they do

Last edited by seasnail2024 (March 24, 2025 00:19:58)

Jareddddddd
Scratcher
1000+ posts

how do I use operators?

operators are used in math! Say you want to know what 3+7 is? You can find this by using the ( + ) operator!

((3) + (7)) // = 10

Here is an example project that uses an operator:
I want Scratch Cat to add 2 numbers.
set [first number v] to [0]
set [second number v] to [0]

First, I'll ask the user for their 2 numbers
ask [Whats your first number?] and wait
set [first number v] to (answer)
ask [Whats your second number?] and wait
set [second number v] to (answer)

Finally, ill tell the player what those 2 numbers added are.

((first number) + (second number)) // this is your operator!
say (join (join (first number) [ + ]) (join (join (second number) [ equals ]) ((first number) + (second number)))

full script:
when green flag clicked
ask [Whats your first number?] and wait
set [first number v] to (answer)
ask [Whats your second number?] and wait
set [second number v] to (answer)
say (join (join (first number) [ + ]) (join (join (second number) [ equals ]) ((first number) + (second number)))
Note that the text “+” isn't an operator, but is just the plain text “ + ”



Last edited by Jareddddddd (March 24, 2025 00:41:41)

-sbossbattle_
Scratcher
100+ posts

how do I use operators?

seasnail2024 wrote:

I dont really understand operators . I dont know what they do
Jareddddddd has a good explanation, however I do believe it might not clear up some confusion.

I'd recommend using the Scratch Wiki (https://en.scratch-wiki.info/wiki/Scratch_Wiki:Table_of_Contents/Operators_Blocks) but I will try to explain the ones that I found confusing at first.

((num) mod (num2)) 

mod takes the first number and divides it by the second number (num/num2) then takes the remainder of the division. Example: 12 mod 4 would be 0 because 12/4 = 3 R 0. 11/3 would be 2 because 11/3 = 9 R 2. (note: R means remainder. You will have seen this if you did long division in elementary)

(join [hello] [world])
The join block adds two strings, which is generally letter text, and puts them together. However, numbers can be treated as strings as well. The output of this operator would be: “helloworld” (without the quotation marks. quotation marks notes that it is a string)

(letter (1) of [world])

The output here would be “w” because “w” is the first letter in “world”.


<<> and <>>
<<> or <>>
<not <>>
<[] contains []?>

These hexagonal blocks are called booleans. They determine if a statement is true or false. The <> and <> block takes two already existing booleans like < contains ?> (which returns true or false if the first input is in the second input. used with strings) and compares them. If they are both true, the <> and <> block returns the “true” value or 1; otherwise, it will return the “false” value or 0. The <> or <> block takes two boolean inputs and compares them. If one or both of them are true, the block will return true or 1 and if both statements are false it will return false or 0. The not <> block takes a boolean and flips the value. If the statement inputted into the not <> block is true, the not <> block will return false, and vice versa.

(round (16.5)) // This rounds the number and returns the rounded number.
([abs v] of (-129)::operators) // The dropdown menu provides multiple functions. Search them up if you are confused.
// By the way, the abs operator returns the absolute value, meaning the positive value of the number. It will always return a positive number and it returns 129 in this case.
seasnail2024
Scratcher
5 posts

how do I use operators?

. Thanks these were helpful! I did not fully understand the Booleans but that is fine! I did understand the mod and +

Last edited by seasnail2024 (March 27, 2025 20:37:30)

762246
New Scratcher
1 post

how do I use operators?

i don't under stand
OsCa11111
Scratcher
4 posts

how do I use operators?

762246 wrote:

i don't under stand
Don't understand what specifically?

Powered by DjangoBB