Basic Mathematical Operation

Hi Everyone,

I’m having a hard time with basic mathematical operations. Even though its basic, when executing the code, its not working. Am i missing something? I am just new to this platform.

export function i18_change(event,$w) {
let ii18 = Number($w(‘#i18’).value);
let ii19 = Number($w(‘#i19’).value);
let iitotal = String(Number(ii18)+Number(ii19));

$w(‘#text13’).text=String(iitotal);
}

The total number is not displaying in text13

Thank you in advance

In JavaScript, you don’t cast items the way you do in Java, which it looks like you’re used to above.

First up, make sure your input field is actually a number field. If not, you can convert to a number either using the way you did, or better yet using parseInt() or parseFloat (if they are decimal places).

Then you don’t add numbers the way you included above. So a reworking of your code would look like:

export function i18_change(event,$w) {
let ii18 = parseInt($w(‘#i18’).value,10);
let ii19 = parseInt($w(‘#i19’).value,10);
let iitotal = ii18+ii19;

$w(‘#text13’).text=iitotal.toString(); // or simply ""+iitotal;
}

Change this to let iitotal = ii18 + ii19;

Leave everything else the same. See if that solves your problem.