New to JS! Returning to Coding after over a decade! Need help with something simple

Hey so I’m tryna throw together a little code for fun and practice and I was rocking along good until I ran into this problem and I got a feeling that like with most things coding the issue is super simple and right in front of me. Can someone explain to me where I went wrong?

So in the below code I am trying to take the 4 user inputed variables (sxp, uxp, ess, gxp) and have the function add them together to a fifth value (txp). That’s all :smiley: Any help is appreciated in advance! :smiley:

function updateTXP() {

// Totals up all the various kinds of xp to total xp

var sxp = parseInt(document.getElementById("sxp").value);

var uxp = parseInt(document.getElementById("uxp").value);

var ess = parseInt(document.getElementById("ess").value);

var gxp = parseInt(document.getElementById("gxp").value);

document.getElementById("txp").value = Math.floor(sxp + uxp + ess + gxp);


I thought maybe it couldn’t handle multiple variable calls in the same line or something so I tried sxp + 2 and it didn’t work either so idk what I’m doing wrong :open_mouth:

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Is your function getting called?

Since you did not post your HTML, can I assume your element with id=txp is an input element?

Do you see any errors in the browser console when the code runs? As @ArielLeslie mentioned, where are you calling updateTXP in your code? I don’t see a call to it with what you posted. Are you using an inline onclick attribute in the HTML?