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

200
Views
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 answers
Answer question

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 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!