0

Here is what I'm trying to do, I want to pass a variable to a function (no problems there). But then I want to use it in an if statement.

colnum(5, 1);


    function colnum (columnnumber, reset)
    {
        var divcount = $('[class^="box"]').length;  
        var columnnumberround = Math.round(divcount / columnnumber);
        var start = 0;
        var end = columnnumberround-1;  

        if (reset=1)
        {
            var i = 0;
            while (i<=columnnumber)
            {
              $('div.box'+start).add($("div.box"+start).nextUntil("div.box"+end)).add($("div.box"+end)).addClass("col"+i);
              $(".col"+i).wrapAll("<div class=column></div>");

              start+=columnnumberround;
              end+=columnnumberround;
              i++;
            }       
        }
        else
        {
            alert("test");
        }
    }
ZygD
  • 22,092
  • 39
  • 79
  • 102
Gregasus
  • 1
  • 2

2 Answers2

2

It should actually be:

if (reset === 1)

JavaScript has two different equality operators, == and ===.
See Which equals operator (== vs ===) should be used in JavaScript comparisons?

Using the type-coercing equality operator (==) can lead to WTFs like this one:

> [[[[[[[2]]]]]]] == 2
  true
Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
1

Your problem is you are using '=' instead of '==' in your IF statements

if (reset=1)

should be

if (reset==1)
arclight
  • 5,299
  • 1
  • 22
  • 26