Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to do exponents?
- djollieboy11
-
Scratcher
15 posts
How to do exponents?
I am working on how to make exponents, and I found that their is no exponent block. would somebody be able to help me do this? This is my code so far:
after all of that, I have an ask script that asks the player what the answer is, but I can't add that because the way I entered this didn't have the blocks.
also, this took forever to make, since I had to type this out and learn this new language that is only in the forums.
when green flag clicked
forever
set [number one] to (pick random (3) to (10)
set [number two] to (pick random (3) to (10)
set [exponent] to (pick random (0) to (5)
set [sum of exponents and second number] to [number two]
if <not <<[exponent] = [0]> or <[exponent] = [1]>>> then
repeat (exponent)
set [sum of exponents and second number] to ((sum of exponents and second number) * (number two))
end
set [sum of exponents and second number] to ((sum of exponents and second number) / (number two))
set [sum of equation] to ((sum of exponents and second number) * (number one))
else
if <[exponent] = [0]> then
set [sum of equation] to (1)
else
if <[exponent] = [0]> then
set [sum of equation] to ((number one) * (number two))
end
end
end
end
after all of that, I have an ask script that asks the player what the answer is, but I can't add that because the way I entered this didn't have the blocks.
also, this took forever to make, since I had to type this out and learn this new language that is only in the forums.
Last edited by djollieboy11 (March 11, 2025 14:55:20)
- Cool_Dude2022
-
Scratcher
500+ posts
How to do exponents?
I am working on how to make exponents, and I found that their is no exponent block. would somebody be able to help me do this? This is my code so far:when green flag clicked
forever
set [number one] to (pick random (3) to (10)
set [number two] to (pick random) (3) to (10)
set [exponent] to (pick random) (0) to (5)
set [sum of exponents and second number] to [number two]
if <not <<[exponent] = [0]> or <[exponent] = [1]>>> then
repeat (exponent)
set [sum of exponents and second number] to ((sum of exponents and second number) * (number two))
end
set [sum of exponents and second number] to ((sum of exponents and second number) / (number two))
set [sum of equation] to ((sum of exponents and second number) * (number one))
else
if <[exponent] = [0]> then
set [sum of equation] to (1)
else
if <[exponent] = [0]> then
set [sum of equation] to ((number one) * (number two))
end
end
end
end
after all of that, I have an ask script that asks the player what the answer is, but I can't add that because the way I entered this didn't have the blocks.
also, this took forever to make, since I had to type this out and learn this new language that is only in the forums.
also sorry, I messed up a little in the code.
You mean something like this? Pretty simple to make: https://scratch.mit.edu/projects/1145491233/editor/
- NoUsername-King
-
Scratcher
100+ posts
How to do exponents?
Okay, exponents can be calculated with
([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)And root can be calculated with this
([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
- djollieboy11
-
Scratcher
15 posts
How to do exponents?
Okay, thank you all for the help! I really appreciate it.
- SuperBee444
-
Scratcher
2 posts
How to do exponents?
Okay, exponents can be calculated withI hope you see this, does root mean square root, and if so, square root of what?([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)And root can be calculated with this([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
- NoUsername-King
-
Scratcher
100+ posts
How to do exponents?
(#5)That can be used for any root, including a square root. A square root would look like this:Okay, exponents can be calculated withI hope you see this, does root mean square root, and if so, square root of what?([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)And root can be calculated with this([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
([e^ v] of (([ln v] of (base)::operators) / [2])::operators)and a cube root would be a 3 and so on.
- Dan_0319
-
Scratcher
16 posts
How to do exponents?
Okay, exponents can be calculated withoh, theres a problem though. how do you do negative bases???([e^ v] of (([ln v] of (base)::operators) * (exponent))::operators)And root can be calculated with this([e^ v] of (([ln v] of (base)::operators) / (root))::operators)
- N8_D_GR8_1
-
Scratcher
1000+ posts
How to do exponents?
-snip-Please avoid posting on other people's topics unless you are helping them. You should create a new topic instead.
oh, theres a problem though. how do you do negative bases???
Here is a fully functional exponent function that I made:
define (x) ^ (y)
if <(x::custom) > [0]> then
set [EXPONENT: output v] to ([e ^ v] of ((y::custom) * ([ln v] of (x::custom)::operators))::operators)
else
if <(x::custom) < [0]> then
if <(y::custom) = (round (y::custom))> then
set [EXPONENT: output v] to (((1) - ((2) * ((y::custom) mod (2)))) * ([e ^ v] of ((y::custom) * ([ln v] of (() - (x::custom))::operators))::operators))
else
set [EXPONENT: output v] to [NaN]
end
else
if <(y::custom) < [0]> then
set [EXPONENT: output v] to [NaN]
else
set [EXPONENT: output v] to (() + <(y::custom) = [0]>)
end
end
end
EDIT: I had to make so many edits to find what Scratch thought was inappropriate language. Apparently “p l e a s e d o n o t p o s t…” is unsuitable language? Man, Scratch really needs to fix the filter.
Last edited by N8_D_GR8_1 (Oct. 31, 2025 14:30:04)
- dspace1015
-
Scratcher
61 posts
How to do exponents?
oh, theres a problem though. how do you do negative bases???Look at my response to this discussion if you need to do negative bases.
- DuraeMan
-
Scratcher
1 post
How to do exponents?
-snip-Please avoid posting on other people's topics unless you are helping them. You should create a new topic instead.
oh, theres a problem though. how do you do negative bases???
Here is a fully functional exponent function that I made:define (x) ^ (y)
if <(x::custom) > [0]> then
set [EXPONENT: output v] to ([e ^ v] of ((y::custom) * ([ln v] of (x::custom)::operators))::operators)
else
if <(x::custom) < [0]> then
if <(y::custom) = (round (y::custom))> then
set [EXPONENT: output v] to (((1) - ((2) * ((y::custom) mod (2)))) * ([e ^ v] of ((y::custom) * ([ln v] of (() - (x::custom))::operators))::operators))
else
set [EXPONENT: output v] to [NaN]
end
else
if <(y::custom) < [0]> then
set [EXPONENT: output v] to [NaN]
else
set [EXPONENT: output v] to (() + <(y::custom) = [0]>)
end
end
end
EDIT: I had to make so many edits to find what Scratch thought was inappropriate language. Apparently “p l e a s e d o n o t p o s t…” is unsuitable language? Man, Scratch really needs to fix the filter.
-snip-Please avoid posting on other people's topics unless you are helping them. You should create a new topic instead.
oh, theres a problem though. how do you do negative bases???
Here is a fully functional exponent function that I made:define (x) ^ (y)
if <(x::custom) > [0]> then
set [EXPONENT: output v] to ([e ^ v] of ((y::custom) * ([ln v] of (x::custom)::operators))::operators)
else
if <(x::custom) < [0]> then
if <(y::custom) = (round (y::custom))> then
set [EXPONENT: output v] to (((1) - ((2) * ((y::custom) mod (2)))) * ([e ^ v] of ((y::custom) * ([ln v] of (() - (x::custom))::operators))::operators))
else
set [EXPONENT: output v] to [NaN]
end
else
if <(y::custom) < [0]> then
set [EXPONENT: output v] to [NaN]
else
set [EXPONENT: output v] to (() + <(y::custom) = [0]>)
end
end
end
EDIT: I had to make so many edits to find what Scratch thought was inappropriate language. Apparently “p l e a s e d o n o t p o s t…” is unsuitable language? Man, Scratch really needs to fix the filter.
But how do you do negative bases with multiple decimals?'
edit - wanted to remove this reply after reading your response to the topic properly, but cant, will make my own topic next time
EDIT 2 - I figured everything out but hoooow doo i deeellleeetttee pooosssts
Last edited by DuraeMan (Nov. 12, 2025 19:58:55)
- N8_D_GR8_1
-
Scratcher
1000+ posts
How to do exponents?
-snip-I'll say it again, please avoid posting on other people's topics unless you are helping them. Create a new topic instead. Your post will actually be more likely to be answered if you create a new topic. This function that I provided does work with decimals and negatives in both the base and the exponent. Just try it out
But how can you make it works with bases that are negative and have multiple decimals?

- N8_D_GR8_1
-
Scratcher
1000+ posts
How to do exponents?
EDIT 2 - I figured it out but hoooow doo i deeellleeetttee pooossstsIt's ok. We all make mistakes (myself included).

- N8_D_GR8_1
-
Scratcher
1000+ posts
How to do exponents?
How about fractional exponents?Same thing. This custom block that I provided is complete and will work with any real number inputs. You can try it out and see for yourself

- void9909
-
Scratcher
11 posts
How to do exponents?
here’s how
if <([10^ v] of ([log v] of (base)) * (exponent)::#59C059) = [Infinity]> then
set answer to ([10^ v] of ([log v] of (base)) * (exponent)::#59C059) :: variables
else
set answer to (join [10^] ([log v] of (base)) * (exponent)) :: variables
Last edited by void9909 (Dec. 27, 2025 20:26:39)
- void9909
-
Scratcher
11 posts
How to do exponents?
here’s howif <not<([10^ v] of (([log v] of (base)) * (exponent))) :: operations = [Infinity])>> then :: control
set answer to ([10^ v] of (([log v] of (base)) * (exponent)) :: variables
else
set answer to (join [10^] [(([log v] of (base) * (exponent)) :: variables
if there’s any glitches then it’s me having trouble having the right colors
- lawaterdog
-
Scratcher
5 posts
How to do exponents?
i thought you can't have negative bases for square roots
- kansea
-
Scratcher
100+ posts
How to do exponents?
i thought you can't have negative bases for square rootsThe square root of -1 is i (imaginary number). I don't know how scratch deals with it, though, because I've never tried it.
- dspace1015
-
Scratcher
61 posts
How to do exponents?
i thought you can't have negative bases for square rootsTechnically you can, but this is where complex numbers come in, though native scratch does not support these.
a^b is only a real number (regular number and not NaN) when either:
- b is an integer
- a is positive
- or a is negative and b is a fraction with an odd numbered denominator. (Such as the cube root b=1/3)
a^b is then negative when:
a is negative and b is odd
a is negative and b is a fraction with an odd numerator
and positive all other scenarios.
This will help any of you reading this post make a function that works for all real numbers, however most uses of exponents will not need to be this well defined, so just go with any of the previous solutions.
It is possible to make an exponent function in scratch that generalizes to all complex numbers, but such a function might be better discussed in a separate topic.
- Discussion Forums
- » Help with Scripts
-
» How to do exponents?