Skip to main content
2 of 2
added more suggestions and correction from comments
Syjin
  • 561
  • 2
  • 8

Some suggestions:

  1. Use more whitespaces and semicolons

  2. Initialise Arrays with []

    var snowcolor = ["#aaaacc", "#ddddFF", "#ccccDD"];
    
  3. Use naming conventions for variables and method names to make them more readable

    initSnow() or init_snow()
    browserInfos or browser_infos
    
  4. In JavaScript it is recommended to combine several variable declerations. So instead of

    var marginbottom
    var marginright
    var timer
    

    you can write

    var marginbottom,
        marginright,
        timer;
    
  5. Instead of passing a string to setTimeout, you can pass a reference to the function directly

    var timer = setTimeout(movesnow, 50);
    
  6. There are some magic numbers in your code, that you might want to extract into variables.

  7. Since JavaScript doesn't have final static variables (afaik), consider marking them via naming conventions. For example:

    var SNOW_MAX_SIZE = 22;
    
  8. The four if statements inside initsnow and movesnow seem to be the same, so you could move them to a seperate function. However, you currently have snowingzone set to a fixed value and you don't change it. So as it is, the if statements are unnecessary.

  9. Some variable names are rather cryptic: x_mv, lftrght, etc.

  10. There are unused variables: e.g. i_snow

  11. The browser identification and the "calculation" of browserok seem to be good candidates for a seperate function.


Update Added 8. - 11.

If you are feeling confident or want to try static code analysis, you might want to look into something like http://www.jslint.com/ or http://www.jshint.com/ . They can warn you about global variables, unused variables and more.

ad 4) As Schism mentioned, this advices may lead to unwanted global variables if you mix up , and ;. So for example:

function foo() {
    var a,
        b; // Oops! ; should be ,
        c; // c is now a global variable
}
Syjin
  • 561
  • 2
  • 8