How to calculate a factorial of a number in thunkable using a loop?

I have tried for days to make a loop in thunkable to get the factorial of a number, I want help, I am a beginner in thunkable, and this screen (that calculates the factorial) is a part of my first real project (a simple calculator)

My code

I am trying to make a variable that get the inputted number from the user, for example: If the user entered the number “5”, so, I am trying to make a loop that subtract 1 integer from that number, so the result will be “4”, then subtract 1 integer from “4”, so the result will be 3, and repeat this till it reach 1, then multiply all these values by the inputted number from user “5”

The link to algorithm: Thunkable

When you post on the forums, you should choose a short title instead of including your entire question in the title. I’ve shortened the title for you.

Please provide a link to the algorithm that you’re using to create a factorial calculator. Because what you have doesn’t seem like it’s following a correct algorithm.

There are also several topics about factorials on the forums so you may want to search for those.

2 Likes

I have tried for days to make a loop in thunkable to get the factorial of a number, I want help, I am a beginner in thunkable, and this screen (that calculates the factorial) is a part of my first real project (a simple calculator)


My code

I am trying to make a variable that get the inputted number from the user, for example: If the user entered the number “5”, so, I am trying to make a loop that subtract 1 integer from that number, so the result will be “4”, then subtract 1 integer from “4”, so the result will be 3, and repeat this till it reach 1, then multiply all these values by the inputted number from user “5”

Please don’t start a second topic for the same issue. You can add more details to your original topic:

In that topic, I asked for a link to an algorithm. Factorials have been studied for centuries so you shouldn’t have to invent a method for calculating them. If you provide a link, I’ll help you figure out the blocks for that algorithm.

The method you described above is actually much harder than the established recursive method.

@matt can you merge this with the original topic (link above)? Thanks!

1 Like

Sorry, it’s the first time for me asking a question on programming forums (like thunkable),
I’ve updated the original topic
and again I am very sorry for the confusion I did :slight_smile:

An algorithm is a step-by-step guide to doing something with code.

What I’m suggesting is that you Google how to calculate factorials recursively. And then use the algorithm (the written steps) as a guide for setting up your blocks in Thunkable.

If you instead want to use your method, you would need to store the current product in a variable so that you can multiply it by the current value in the loop (5, then 4, then 3, etc.).

1 Like

Thanks sir :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.