# Thread: Need help wt Javascript

1. ## Need help wt Javascript

Hello,
I trying to create a calculator for a game, and i stuck on exp matching, i cant understand how its works .
I managed to create code who how many exp needed to reach certain level :
Code:
```LVL=new Array();
LVL[1]=128;
LVL[0]=128;
m=.05;
for (i=1;i<101;i++) {
if (i>1) {
LVL[i]=Math.floor(LVL[i-1]+(LVL[i-1]*m));
m=m+.0015;
}
}```
I need exp to next level and exp difference.
Here is formula:
+-----+---+-------+----------+
|Level|Exp |Exp diff|Exp needed|
+-----+---+-------+----------+
|LVLX-|-A-|---B---|----C-----|
+-----+---+-------+----------+
|LVLY-|-D-|---E---|----F-----|
+-----+---+-------+----------+

LVLY exp needed = D-A
LVLY exp diff = B+F

F=D-A D-E=128
E=B+F A-B=128
D-E=A-B
(levels starts from1 and till 99)
Thanks.

2. From your calculations, it seems that the following table will match.

+-----+-----+--------+----------+
|Level| Exp |Exp diff|Exp needed|
+-----+-----+--------+----------+
|LVL0 | 128 | . 0 . .| . .1 . . |
+-----+-----+--------+----------+
|LVL1 | 129 | . 1 . .| . .2 . . |
+-----+-----+--------+----------+
|LVL2 | 130 | . 2 . .| . .3 . . |
+-----+-----+--------+----------+
|LVL3 | 131 | . 3 . .| . .4 . . |
+-----+-----+--------+----------+

3. No, i created what table to show witch match must be done to calculate.
Here is javascript code what matches exp amount for levels:
Code:
```LVL=new Array();
LVL[1]=128;
LVL[0]=128;
m=.05;
for (i=1;i<101;i++) {
if (i>1) {
LVL[i]=Math.floor(LVL[i-1]+(LVL[i-1]*m));
m=m+.0015;
}
}```

4. F=D-A D-E=128
E=B+F A-B=128
D-E=A-B

You have A and D
A = 128
D = 134

F=D-A = 6
or, Needed = Exp(n)-Exp(n-1)

D-E=128 or D=128+E or E=D-128
In other words, Diff = Exp-128
E=6 and by the same logic, B=0

Diff = Exp-128
Needed = Exp(n)-Exp(n-1)

+-----+-----+--------+----------+
|Level| Exp |Exp diff|Exp needed|
+-----+-----+--------+----------+
|LVL0 | 128 | . .0. .| . . 0. . |
+-----+-----+--------+----------+
|LVL1 | 134 | . .6. .| . . 6. . |
+-----+-----+--------+----------+
|LVL2 | 140 | . 12. .| . . 6. . |
+-----+-----+--------+----------+
|LVL3 | 147 | . 19. .| . . 7. . |
+-----+-----+--------+----------+

5. I know thanks, but i need to create javascript code who will do what match and i stuck on what part, i never created whose matching things in javascript, i only managed to create current exp

6. Well you now have the formulas that you need.

Diff = Exp-128
Needed = Exp(n)-Exp(n-1)

7. yes i know them but i don't know how to white them using javascript.

8. Here is your existing code, rewritten in a slightly better way.

Code javascript:
```var lvl = [
{exp: 128, diff: 0, needed: 0},
{exp: 128, diff: 0, needed: 0}
],
m = 0.05,
i,
oldLvl;
for (i = 2; i <= 100; i += 1) {
oldLvl = lvl[i - 1];
lvl[i] = {};
lvl[i].exp = Math.floor(oldLvl.exp + (oldLvl.exp * m));
m = m + 0.0015;
}```

Here is that same code with my suggested updates.

Code javascript:
```var lvl = [
{exp: 128, diff: 0, needed: 0},
{exp: 128, diff: 0, needed: 0}
],
m = 0.05,
i,
oldLvl,
exp;
for (i = 2; i <= 100; i += 1) {
oldLvl = lvl[i - 1];
lvl[i] = {};
exp = Math.floor(oldLvl.exp + (oldLvl.exp * m));
lvl[i].exp = exp;
lvl[i].diff = exp - 128;
lvl[i].needed = exp - oldLvl.exp;
m = m + 0.0015;
}```

9. Wow!
Thank you very much

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•