# Return the sum of all digits of a number?

0 favourites
• 3 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
• For example, the sum of all digits of 123 is 1+2+3=6, 4510 is 4+5+1+0=10.

Is there any built in expression that can do that? If not, what is the standard way other than a for loop to do that? Thanks.

• If I remember correctly this was part of either the basic or intermediate algorithm scripting when I was doing my frontend development certification through Free Code Camp. I've just googled it - check this link out:

I'm afraid that loops are the most efficient way to perform this type of operation!

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• A cheating way to calculate the digital root is to break it into a string, take each position as a number and call a function.

Here's a way of doing it.

You need a new project, a function added, a text input added and a text added (default names)

With this example, it will self update the digital root as you type each number in the text box.

• 3 posts