Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Please help. What does if (--) mean in javascript

What does if (--) mean in javascript? i have no idea how to search from google.

1 Answer

Could you elaborate a bit further?

On the first look "if" means a if statement block and the (--) just shows where the statement is evaluated and nothing more. ยดยดยดjs if(--)

Check [W3schools](http://www.w3schools.com/js/js_if_else.asp) for more info on if statements.

Hope this helped.

Hi Nejc

Below is the javascript code. I was stuck at if (--c). Hope you can clear my problem.

      var mspf = 60;  // MS per frame
        var trailLen = 15; // Characterss per 'strand'
        var spawnTime = 20;
        var theLetters = "404 page";

        var fadeTime = mspf * trailLen * 2;  // time until trail.remove()
        function rain(){
          var randId = Math.floor(Math.random()*1000);
          myFun(trailLen,randId);


          setInterval(function(){
            $("div[id="+randId+"]").remove();
          },fadeTime);
        }

        function myFun (c,uid) {
        var id = "";
          setTimeout(function(){
            if (c == trailLen){
              var y = Math.floor(Math.random() * ($("#out").height() / 10) ) * 12; // height / 10 * 12 ensures a small space between trails, and also prevents overlapping (in theory) 
              var x = Math.floor(Math.random() * ($("#out").width() / 10) ) * 12;
              var scale = (Math.random() * 12) + 8;
              $("#out").append("<div style='font-size:"+scale+"px;top:"+y+"px;left:"+x+"px;' class='trail' id='"+uid+"'></div>"); // add .trail
            }
            if (--c){myFun(c,uid);}
            $("div[id="+uid+"]").append("<span>"+theLetters.substr(Math.floor(Math.random()*theLetters.length),1)+"</span><br>"); // adds spans to .trail 


          }, mspf);
        }

      setInterval(rain,spawnTime);
    }