Skip to content Skip to sidebar Skip to footer

JSLint Validation Error "combine This With The Previous Var Statement"

JSLint Validation error 'combine this with the previous var statement' How do I combine this so I don't get JSLint Validation error? I get the validation error on the lines of code

Solution 1:

This error means that you have multiple var statements in some of your functions, such as:

var x = 1;
var y = 2;

JSLint wants you to combine the variable declarations in a single var statement like:

var x = 1,
    y = 2;

Solution 2:

I think JSLint is referring to these few lines of your code (towards the bottom of the code you have provided):

var userEnteredDate = new Date($('#dateOfLastAccident').val()); // variable that stores user entered date
var today = new Date(); 
var minutes = 1000 * 60; // calculation used to convert miliseconds to minutes
var hours = minutes * 60; // calculation used to conver minutes into hours
var days = hours * 24; // calculation used to convert hours to days
var years = days * 365; // calculation used to convert days into years
var daysSinceAccident = Math.floor((today.getTime() - userEnteredDate.getTime()) / days); // calculation used to find the difference between current date and user entered date as a whole number
var className = getClassName(daysSinceAccident); // variable clasName finds the correct css style to apply based on daysSinceAccident

You can avoid declaring them multiple times by delimiting each variable with a comma:

var userEnteredDate = new Date($('#dateOfLastAccident').val()),
    today = new Date(),
    minutes = 1000 * 60,
    hours = minutes * 60,
    days = hours * 24,
    years = days * 36,
    daysSinceAccident = Math.floor((today.getTime() - userEnteredDate.getTime()) / days),
    className = getClassName(daysSinceAccident);

Post a Comment for "JSLint Validation Error "combine This With The Previous Var Statement""