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 = newDate($('#dateOfLastAccident').val()); // variable that stores user entered datevar today = newDate(); 
var minutes = 1000 * 60; // calculation used to convert miliseconds to minutesvar hours = minutes * 60; // calculation used to conver minutes into hoursvar days = hours * 24; // calculation used to convert hours to daysvar years = days * 365; // calculation used to convert days into yearsvar daysSinceAccident = Math.floor((today.getTime() - userEnteredDate.getTime()) / days); // calculation used to find the difference between current date and user entered date as a whole numbervar 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 = newDate($('#dateOfLastAccident').val()),
    today = newDate(),
    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""