0

my aim is to make a calculator which will allow the user to input their level and how many runes(Elden Ring's in game currency) they have currently. I then want to have my code calculate how many levels the user can purchase with the amount of runes they have.

For example, let's say I am level one and I have 2,000 runes, judging by the array we have called 'runearray' the user will only be able to level up to level 3. Am I going the right way about implementing this? Here's a pic of what the user will see...

User's POV

        <div class="calcrune col-md-12">
            <span class="runecalc">Current Level: <input id="levelcurrent1" type="text" min="1" max="712"></span>
            <span class="runecalc">Current Runes: <input id="runecurrent1" type="text" min="1" max="712"></span>
            <button class="runecalc" onclick="levelCalc()">Calculate Levels</button>
            <span>Level Upgrades: <span id="runes1"></span></span>
        </div>
function levelCalc() {
        var levelcurrentstring = document.getElementById('levelcurrent1').value;

        var levelcurrentminus1 = parseInt(levelcurrentstring);

        var runecurrentstring = document.getElementById('runecurrent1').value;

        var runecurrentvalue = parseInt(runecurrentstring);

        var levelcurrent = levelcurrentminus1 - 1;

        const runearray = [/* level 1 to 2 = */ 673, /* level 2 to 3 = */ 689, /* level 3 to 4 = */ 706....
        ];

        var newrunearray = runearray[levelcurrent];

        for (i = levelcurrent; i < runecurrent; i++) {
            var newrunearray = newrunearray + runearray[levelcurrent + 1];
        }

        document.getElementById('runes1').textContent = newrunearray;
}
Diar Tylr
  • 1
  • 2
  • *"Am I going the right way about implementing this?"* - Does your implementation work? When you debug, does any given operation produce an unexpected result? What specifically isn't working as expected? – David Apr 21 '22 at 15:53
  • Hi @David, no unfortunately this doesn't work whatsoever. It gives me random numbers all above 100,000 which shouldn't even be possible. I have no idea what or how I need to do this tbh – Diar Tylr Apr 22 '22 at 08:44
  • In that case now is the time to [start debugging](https://stackoverflow.com/q/25385173/328193). Using your browser's debugging tools you can step through the code line by line as it executes, observing the exact runtime behavior and exact changing values of your variables. (Even without the step debugger, you can litter the code with `console.log` statements to output useful information about those values.) When you do this, which operation first produces an unexpected result? What were the values used? What was the result? What result was expected? Why? – David Apr 22 '22 at 11:02
  • Hey mate, just got it fixed there thanks. I just used a do while loop instead of the for loop and I was able to get it working – Diar Tylr Apr 22 '22 at 12:25

0 Answers0