Intermediate [Exercise 2: Default & Assign] (Training slides exercise)

Create an input field with the data type ‘currency’ and a default value of zero (remember to use the assign attribute in order to store the default value in the database). If the entered value in the input field is positive, create a variable called ‘financial_result’ and assign the text string ‘profit’ to it, if the value is negative the text string will be ‘loss’ and if the value is zero the text string will be ‘result’.

Finally print the following text in which the second word will be the variable ‘financial_result’ and the final value will be the input value entered previously:

“The profit/loss/result for the current financial year is (input value entered)”

You should get something like this at the end (with wording changing when different values are entered):

|302px;x85px;

Solution:

{% input custom.profit.cy as:currency default:0 assign:profit %}

{% if profit > 0 %}
  {% assign financial_result = 'profit' %}
{% elsif profit < 0 %}
  {% assign financial_result = 'loss' %}
{% else %}
  {% assign financial_result = 'result' %}
{% endif %}

The {{ financial_result }} for the current financial year is {{ profit }}