Due to increasing spam attacks, forum registrations are currently paused to keep our community safe and spam-free. Come hang out and stay connected with us on the SimHub Discord: https://discord.com/invite/nBBMuX7!
Catch you on Discord — and thanks for understanding!
Catch you on Discord — and thanks for understanding!
Notifications
Clear all
Topic starter
29/03/2024 9:49 am
I have two variables that I would like to add in javascript but unfortunately I cannot find the syntax.
Example:
toto = '1';
tata = '2';
result = toto + tata;
return result;
Unfortunately the result obtained is 12 whereas I would like it to be 3.
Do you have an idea ?
Thanks in advance.
31/03/2024 12:15 am
You placed the 1 and 2 between '' in the variables.
Then it's a sort of name instead of a number, and cant be calculated. It simply places the names after eachother. So you get 12. When you name them x and y you get xy
Without the '' it becomes a number
This should work:
var toto = 1;
var tata = 2;
var result = '';
result = toto+tata;
return result;
or:
var toto = 1;
var tata = 2;
return toto+tata
This post was modified 1 year ago 2 times by Smiddyy