math - Meteor.js the plus operator -


i'm writing simple program teach basic of input, form , template , sessions using meteor.

 if (meteor.isclient) {   session.set('value',0);    template.hello.helpers({   result: function(){    return(session.get('value')); } });   template.hello.events({   'submit form': function(event) {    event.preventdefault();    var s1=event.target.num1.value;   var s2=event.target.num2.value;    var s = s1 - s2;   session.set('value',s);  } 

}); }

the problem when operator changed + seems concatenate 2 numbers. other basic operators work fine. bug ? simplest example can teach students , stuck.

i'm using mac 10.6.8 , meteor 1.1.0.2

it's hard tell without seeing jsfiddle bet problem 1 of values or both being passed in string.

the plus sign concatenation operator js , perform type coercion number string, if both not numbers , 1 string. - operator perform other way, , turn strings numbers.

check data types being passed in , makes sure they're both numbers. if aren't, use parseint turn them numbers.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -