Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda