I am trying to create a MPL (multiple price list.) on otree (using PyCharm). For one of my app (WTP) I wrote this code on the html "folder" (using Javascript):
{% if choice.0 > 0 %} If you are paid {{choice.0}} points for this item, would you accept?
{% elif choice.0 == 0 %}
If you are paid {{choice.0}} points for this item, would you accept?
{% elif choice.0 < 0 %}
If you have to pay {{choice.0}} points for this item, would you accept?
{% endif %}
the different choices being defined on pages.py:
self.participant.vars['choices'] = [
[+30, "choice1", "choice1-yes", "choice1-no"],
[+20, "choice2", "choice2-yes", "choice2-no"],
[+10, "choice3", "choice3-yes", "choice3-no"],
[0, "choice4", "choice4-yes", "choice4-no"],
[-10, "choice5", "choice5-yes", "choice5-no"],
[-20, "choice6", "choice6-yes", "choice6-no"],
[-30, "choice7", "choice7-yes", "choice7-no"],
However, I would like all the numbers to appear without the "minus" sign on the participants' screen. How can I modify my Javascript code s.t. -10 becomes 10, -20 becomes 20 and -30 becomes 30.
Thanks!
Use Math.abs():
Math.abs(-30) // 30
Edit: It seems that your syntax is of django templates but you ask about javasscript. if thats the case use django mathfilters