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

201
Visualizações
What is the best way to return a specific number value for a specific number input?

I am trying to update a specific number value based on another specific number value in javascript

I am looking for the best way to use javascript so that when the 'BPM' value changes, the 'time added' value would also change to match the following values:

BPM : Time added

-52 : 4.75

-48 : 4.5

-44 : 3.8

-40 : 3.2

-36 : 2.5

-32 : 2

-28 : 2

-24 : 1.5

-20 : 1.25

-16 : 0.85

-12 : 0.75

-8 : 0.5

-4 : 0.25

0 : 0

4 : 0

8 : -0.2

12 : -0.4

16 : -0.6

20 : -0.6

24 : -0.8

28 : -0.9

32 : -1.1

36 : -1.1

40 : -1.2

44 : -1.35

48 : -1.42

52 : -1.55

I believe this could be done with a series of if..else if statements, but that seems very unwieldy.

Here is the code I am using to update the BPM with a button click:

     function increase() {
        // Increase the playing speed by approx 1 BPM
        rate += 0.03808;
        bpm += 4;
    }

    function decrease() {
       // Decreasing the playing speed by 1 BPM
        if (rate > .25)
          rate -= 0.03808;
          bpm -= 4;
    }

I would like to add another variable called 'time change' that maps the value of the bpm to the correct time value in the list above each time the bpm is increased or decreased.

thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can do so with a javascript object. Just give each BPM a value in an object. Then attach an event handler to the BPM input and check to see if that value exists and use it. I'm just logging it for testing purposes.

let times = {
  "-52": "4.75",
  "-48": "4.5",
  "-44": "3.8",
  "-40": "3.2",
  "-36": "2.5",
  "-32": "2",
  "-28": "2",
  "-24": "1.5",
  "-20": "1.25",
  "-16": "0.85",
  "-12": "0.75",
  "-8": "0.5",
  "-4": "0.25",
  "0": "0",
  "4": "0",
  "8": "-0.2",
  "12": "-0.4",
  "16": "-0.6",
  "20": "-0.6",
  "24": "-0.8",
  "28": "-0.9",
  "32": "-1.1",
  "36": "-1.1",
  "40": "-1.2",
  "44": "-1.35",
  "48": "-1.42",
  "52": "-1.55"
};

let bpmInput = document.querySelector(".bpm");
bpmInput.addEventListener("input", function() {
  _time = times[bpmInput.value];
  if (_time) {
    console.log(_time)
  }
});
<input type="text" class="bpm">

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