Skip to main content
All CollectionsBuilding an Experience
How to Create a Calculator Using Conditional Logic?
How to Create a Calculator Using Conditional Logic?
Outgrow Team avatar
Written by Outgrow Team
Updated over 7 months ago

You can use basic operators like +, -, x, and / by typing them out on the keyboard. You can easily build simple cost and savings calculators with these basic operators. If you would like to use advanced operators like ^ and log, you can use them too. Simply type them out on your keyboard.

However, if you want to use more complicated formulas, read the sections below.

Using If-Then-Else Statements

To use conditional expressions, you need to use a formula of type x ? y : z. Let's use an example to understand it better:

Assume you want to calculate the risk of hitting your head on the ceiling, and it depends on your height. You will ask a question "What is your height?" and assign a risk value based on the answer.

The expression will take the form: If my height is less than 4.5 feet, then my risk of hitting my head on the roof is 50%, else it is 90%. To write this expression in the formula builder, just write:

Q1 < 4.5 ? 50 : 90

Here, "?" becomes the expression for "then," and ":" becomes the expression for "else."

Using Else-If Statements

This was a simple example, but in a real situation, it may be more complicated. Say there was another question that asked if you have good eyesight. [if eyesight is good, then we assign a value of 1, else 0]

So if a person's height is greater than 4.5 feet but has good eyesight, then their risk is 70% (if they have bad eyesight, then the risk is 90%).

In this case, we must use a nested if-else statement to account for the new question. Here is what it will look like:

Q1 < 4.5 ? 50 : (Q2 == 1 ? 70 : 90)

This statement can be paraphrased as follows: if height is less than 4.5 feet, the risk is 50%; if height is greater than 4.5 feet and eyesight is good, then the risk is 70%; otherwise, it is 90%.

Just like this, you can create as many else-if statements to account for more variables and complications.

Feel free to reach out if you need more help. In case the documentation below doesn't answer your questions about your formula, feel free to email Questions@Outgrow.Co. Many of us are mathematics majors and will be delighted to help :)

Did this answer your question?