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