Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
Absolute value Javascript

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!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!