0

I am making a UI in this link pluker link using the following code for a function:

function span1(left1, width, id, color11) {

    if (id == 1) {
        var sum = 0;
        if (sum < width)
            sum = width;

        width5 = left1 + sum;
        console.log(width);
    } else if (id == 2) {
        var sum2 = 0;
        left1 = width5;
        if (sum2 < width)
            sum2 = width;

        width1 = left1 + sum2;
    } else if (id == 3) {
        var sum1 = 0;
        if (sum1 < width)
            sum1 = width;
        left1 = width1;
        width2 = sum1 + left1;

    } else if (id == 4) {
        left1 = width2;
        width3 = left1 + width;
    } else {
        left1 = width3;
    }

When the id is changing form 1 to 2 its giving my left1 value as 6620 which is concatenation of left1=66 and width=20. Could you please help me? Thanks in advance.

www139
  • 4,960
  • 3
  • 31
  • 56
deepak
  • 77
  • 7

1 Answers1

3

you just need to use parseFloat() or parseInt()

function span1(left1, width, id, color11) {
   left1 = parseInt(left1 , 10);
   width = parseInt(width , 10);
   // So on ....

or you can use parseFloat() up to what you need .. you can read Behavior difference between parseInt() and parseFloat()

Community
  • 1
  • 1
Mohamed-Yousef
  • 23,946
  • 3
  • 19
  • 28