Can I make the bot do calculations?
Of course, you can! It’s a bot, what did you expect? ;)
But it does need a bit of an adventurous mind, as you will need to write some JavaScript code!
We will make use of the Script variables.
Step 0: enable developer mode
Step 1: create step variable(s) to be used as input for our calculation:
![](https://academy.quriobot.com/how-to-build-an-advanced-bot/can-i-make-the-bot-do-calculations/27485.en-us_hub509b67a8700b1798d960af48ab874f3_68878_20x0_resize_box_3.png)
Step 2: create script variable which does the calculation using the other variables:
![](https://academy.quriobot.com/how-to-build-an-advanced-bot/can-i-make-the-bot-do-calculations/27486.en-us_hu9b885f0f7c2dd5e84d6cb0248f585a3b_117691_20x0_resize_box_3.png)
function(callback, variables) {
// The `callback` argument has to be called with the result value in order to support the async operations. The `variables` argument is an object containing other variables
var number = parseFloat(variables.number.value);
callback(number * 5)
}
this is the actual calculation:
- First it takes the input given in Step 1 (a number question in the example);
- It then multiplies it by 5 in the second line.
Step 2: use the calculations in the bot:
Following the example above is the calculation, which can be added as below (like: {{calculation}}). This variable can be used in the chat texts, response messages, response connections.
![](https://academy.quriobot.com/how-to-build-an-advanced-bot/can-i-make-the-bot-do-calculations/27487.en-us_hu948723b7ce380a04e43f1033f1f96faf_39860_20x0_resize_box_3.png)
Which will then show the calculated value!
Note: if you want to use input from multiple steps, simply add more variables of the type you need.
If you want to save this calculation along with the response and/or use this calculation result in the advanced conditions for the jump logic or the response connections, you can use Goto step with the value setting as {{calculation}}:
![](https://academy.quriobot.com/how-to-build-an-advanced-bot/can-i-make-the-bot-do-calculations/27488.en-us_hudc7a7da5161b3840becce0a613ee0d4f_167648_20x0_resize_box_3.png)
![](https://academy.quriobot.com/how-to-build-an-advanced-bot/can-i-make-the-bot-do-calculations/27489.en-us_hu7962ef29a742ef56600c5144755f007f_382398_20x0_resize_box_3.png)