Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda