FANDOM

231 Pages

() * ()
46pxpx
Category Operators
Type Reporter

The () * () block is an Operators block and a Reporter block. The block multiplies the two values and reports the result.

The numbers can be typed directly into the block, or Reporter blocks can be used instead.

This block can be stacked inside itself - this can be used to fit more numbers in or calculate exponents.

Example Uses Edit

* 0 1 2 3 4 5 6 7 8 9 10 11 12
0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9 10 11 12
2 0 2 4 6 8 10 12 14 16 18 20 22 24
3 0 3 6 9 12 15 18 21 24 27 30 33 36
4 0 4 8 12 16 20 24 28 32 36 40 44 48
5 0 5 10 15 20 25 30 35 40 45 50 55 60
6 0 6 12 18 24 30 36 42 48 54 60 66 72
7 0 7 14 21 28 35 42 49 56 63 70 77 84
8 0 8 16 24 32 40 48 56 64 72 80 88 96
9 0 9 18 27 36 45 54 63 72 81 90 99 108
10 0 10 20 30 40 50 60 70 80 90 100 110 120
11 0 11 22 33 44 55 66 77 88 99 110 121 132
12 0 12 24 36 48 60 72 84 96 108 120 132 144

In many projects, numbers must be multiplied; this block will do the job.

Some common uses for the () * () block:

• Scripts in calculator simulations

<scratchblocks> set [result v] to ((a) * (b)) </scratchblocks>

• Multiplying lists of numbers

<scratchblocks> set [result v] to (1) set [item v] to (1) repeat (length of [numbers v]) set [result v] to ((result) * (item (item) of [numbers v])) change [item v] by (1) end </scratchblocks>

• Math formulas

<scratchblocks> ([sqrt v] of ((((y1) - (y2)) * ((y1) - (y2))) + (((x1) - (x2)) * ((x1) - (x2))))) //Pythagorean Theorem </scratchblocks>

• Score multipliers

<scratchblocks> set [score v] to ((score) * (2)) </scratchblocks>

<scratchblocks> when gf clicked set [velocity v] to  forever if <key [space v] pressed?> change [velocity v] by (2) set [velocity v] to ((velocity) * (0.87)) //simulates friction slowdown </scratchblocks>

• 3D Projects

Scientific Notation Edit

In Scratch 1.4 and previous versions, it sometimes converts very large numbers into scientific notation to save space. Scientific notation is simply the number in the form a*10b. These can be converted to a normal number by performing any mathematical function on it, such as adding. So if a variable named "number" has a value of 3*103 and you want to display it as a normal number, you can change it by: <scratchblocks>((number) + (0))</scratchblocks> It will then report "3000".

Workaround Edit

Main article: List of Block Workarounds

With natural numbers, this block can be replicated with the following code, assuming a is the first number and b is the second number: <scratchblocks> set [product v] to  repeat (b) change [product v] by (a) </scratchblocks>

The following code works for all cases (with the conditional). It divides by the reciprocal, the equivalent of multiplying. <scratchblocks> if <(b) = (0)> then set [product v] to  else set [product v] to ((a) / ((1) / (b))) end </scratchblocks>

The following code accepts negative numbers with decimals:

<scratchblocks> delete (all v) of [num1 numbers v] //setup delete (all v) of [num2 numbers v] delete (all v) of [product digits v] set [product v] to  set [dec pos 1 v] to  set [dec pos 2 v] to  ask [num1] and wait if <(answer) < > then set [count v] to  set [no 1 negative v] to [y] else set [count v] to  set [no 1 negative v] to [n] end repeat (length of (answer)) change [count v] by (1) if <not <(letter (count) of (answer)) = [.]>> then add (letter (count) of (answer)) to [num1 numbers v] else set [dec pos 1 v] to ((length of (answer)) - (count)) end end ask [num2] and wait if <(answer) < > then set [count v] to  set [no 2 negative v] to [y] else set [count v] to  set [no 2 negative v] to [n] end repeat (length of (answer)) change [count v] by (1) if <not <(letter (count) of (answer)) = [.]>> then add (letter (count) of (answer)) to [num2 numbers v] else set [dec pos 2 v] to ((length of (answer)) - (count)) end end set [num1 v] to (num1 numbers) set [num2 v] to (num2 numbers) repeat (num1) //start change [product v] by (num2) end set [decimal position v] to ((dec pos 1) + (dec pos 2)) set [count v] to  repeat (length of (product)) change [count v] by (1) add (letter (count) of (product)) to [product digits v] end if <not <(decimal position) = >> then insert [.] at ((length of [product digits v]) - ((decimal position) - (1))) of [product digits v] end if <<<(no 1 negative) = [y]> or <(no 2 negative) = [y]>> and <not <<(no 1 negative) = [y]> and <(no 2 negative) = [y]>>>> then insert [-] at (1 v) of [product digits v] end set [product v] to (product digits) </scratchblocks>

See Also Edit

Community content is available under CC-BY-SA unless otherwise noted.