Why am I getting a concatenated value in this loop

deepak

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.

Mohamed-Yousef

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()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why am I getting a number and not a concatenated string?

Why I am getting such strange behavior value for loop?

Why I am not getting the value

why I am not getting error in this java for loop?

Why am I getting an Infinite loop in javascript

Why am I getting an IndexError from a for loop?

Why am I getting 46 errors with this for loop?

Why am I getting null as a value of array?

Why am I getting an NaN value?

Why am I getting Promise instead of a value?

Why am I getting parameter value as null?

Why am I getting the previous value of state?

Why am I getting this big value at the end?

Why am I getting an ‘IndexError: string index out of range’ when I use a concatenated dataframe

Why after the while loop I am only getting last row value?

Why am I only getting one value returned for my latitude and longitude? (For loop issue)

Why I am getting NaN when I toggle the loop?

Why am I getting a change in list elements but not the subtracted value of that element, when using for loop and print(my_list[i-1])

Why am I getting an error with Dir in a VBA loop?

Why am I getting segmentation fault in my while loop?

Why am I getting a missing return at the end of function in a for loop

Why I am getting "none" every time the loop is executed once?

Why am I getting a segmentation fault from scanf loop?

Why am I getting an infinite loop from this while inside a for?

Why am I getting an invalid syntax error in a for loop?

why I am getting undefined result with for loop function?

Why am I getting a index error for my loop in python?

Why am I getting an infinite loop with this React code?

Why am I getting a segmentation fault at this while loop?