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 8: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.
	                                                        30/03/2024 11:15 pm  
		                                    
        
        
        
    
    	            
	            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 2 years ago 2 times by Smiddyy