0
var a = {
  one : 1,
  arr : ['one','two','three'],
  doThis : function(){return 20;},
  two : 2
};

var html = 'a.one = ' + a.one + '<br/>';
html += 'a.arr[0] = ' + a.arr[0] + '<br/>';
html += 'a.doThis() = ' + a.doThis() + '<br/>';
html += 'a.two = ' + a.two;
html += 'a.one + a.arr[0] + a.doThis() + a.two = ' + a.one + a.arr[0] + a.doThis() + a.two + '<br/>';

var no = parseInt(a.one);
var no1 = parseInt(a.doThis());
var no2 = parseInt(a.two);

html += 'a.one + a.arr[0] + a.two = ' + no + no1 + no2 + '<br/>';
document.getElementById('content').innerHTML = html;
​

OUTPUT:

a.one = 1
a.arr[0] = one
a.doThis() = 20
a.two = 2a.one + a.arr[0] + a.doThis() + a.two = 1one202
a.one + a.arr[0] + a.two = 1202

I wish to add the first, third and the fourth numbers so that the answer is 23 ....
But all I do I concatenation .... i.e. 1202

Please help !

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by urtrivedi
0
var total=no+no1+no2;
html += 'a.one + a.arr[0] + a.two = ' + total + '<br/>';
document.getElementById('content').innerHTML = html;
​
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.