How to create a calculator using assignments and expressions?

Creating a calculator involves two steps. 

1. Assignment 2. Expressions

Assignment: 

The first step in the calculator is the assignment. To set a score or value for an answer, you have to set it from the Assignment, as shown in the screenshot below. Default Assignment is available for number answers. Components include 'Number', 'Rating', 'Opinion Scale'. Meaning the answered value is taken as a score. 

Default Assigment

You can also add your own scoring/custom scoring for answers by clicking the  'Add Assignment' button. This is useful for assign scores for 'Text' answers. 

When an assignment is added for a question, the scores are calculated and added to a default variable called 'Score' in 'Expressions' when the question is answered. Let us look at how 'Expressions' help. 

Expressions: 

Expressions are useful for writing formulas for calculation. You can access it from the 'Variables & Expressions' in Settings. Screenshot below. 

By default, BlockSurvey has a created a default expression 'Score' - which sums the scores of all questions. You can write your own expressions and formulas based on your requirements. Click on 'Add Expression' and give a name and write to them by selecting 'questions' and 'expressions.' Use the '@' symbol to select them from the dropdown. Screenshot below. 

All mathematical operations supported in Javascript is supported in 'Expressions. Refer following links for reference.' Operators, Comparisons, and Math

Example: 

Now that we have understood the basics let's create a simple Return on Investment(ROI) Calculator

What is the ROI? 

Return on Investment ( ROI) is a financial metric commonly used to calculate an investment return likelihood. It's a ratio that compares an investment's gain or loss to its expense. It is useful in calculating future returns from a stand-alone investment compared to multi-investment returns.

ROI = (Net Return on Investment / Initial of Investment) X 100

Let's create questions to accept 'Initial Investment,' 'Final Investment' and calculate and show 'Return on Investment.' 

You can also import this file to see the entire work. https://envl.app/blocksurvey/pIeXHq!mDc2t2GFRR9jym8d

Download it and import from the 'Settings' -> 'Import.' 

Assignment: 

Question 1

Question 2 

ROI Question: You can see how '@' has been used to select the expressions. 

Expressions: 

You can observe the expression written for net-return and how net-return is later used in ROI expression. 

Here is the form link to test live 👉 https://blocksurvey.io/survey/1DnQ8ArNjQU8Xrf97BbaNNLbFeJTksxHYC/9bdfb7c1-069d-48ff-81ff-00babf15a91a

If you have any questions, feel free to write to [email protected] 

Still need help? Contact Us Contact Us