2013-10-11 5 views
6

JSLint सत्यापन त्रुटि "पिछले वर बयान के साथ इस गठबंधन"JSLint सत्यापन त्रुटि

मैं इस तो मैं नहीं मिलता है JSLint सत्यापन त्रुटि को कैसे संयोजित कर "पिछले वर बयान के साथ इस गठबंधन"? मुझे getClassName फ़ंक्शन में कोड की पंक्तियों पर सत्यापन त्रुटि मिलती है।

$(document).ready(function() { 
'use strict'; 
// This function is used to calculate the date 
function dateString(dateToDisplay) { 

    var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 
     'July', 'August', 'September', 'October', 'November', 'December'], 
     dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 
      'Friday', 'Saturday']; 

// Use current date if no parameter or bad date provided 
    if (dateToDisplay === undefined || !(dateToDisplay instanceof Date)) { 
     dateToDisplay = new Date(); 
    } 

    return dayNames[dateToDisplay.getDay()] + ', ' // Day of week: Sunday 
     + monthNames[dateToDisplay.getMonth()] + ' ' // Name of month: July 
     + dateToDisplay.getDate() + ', ' // Day of month: 20 
     + dateToDisplay.getFullYear(); // Year: 1969 
} 


$('#safetyRecord').hide(); // hides the header with the id of safetyRecord until we are ready to display it later in the code 
$('#today').text(dateString()); // changes the text in the span with the id of today to the current date using the dateString function 
function getClassName(days) { // this function determines which css style to apply to the id daysSinceLastAccident and the id message based on the number of days since last accident 
    if (days >= 730) { return "great"; } 
    if (days >= 180) { return "good"; } 
    if (days >= 60) { return "marginal"; } 
    if (days >= 14) { return "poor"; } 
    if (days >= 0) { return "disaster"; } 
} 

$('#checkRecord').click(function() { // when the checkRecord button is clicked the number of days since last accident is calculated, storing the number in a variable. 
    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 
    $('#daysSinceLastAccident').text(daysSinceAccident); // replaces the content of the element with id daysSinceLastAccident with the number of days accident-free 
    $('#daysSinceLastAccident').removeClass(); 
    $('#daysSinceLastAccident').addClass(className); // applies css class style to element with id daysSinceLastAccident 

    $('#safetyRecord').show(); // Using the same timeframes, a custom message styled with the appropriate css class in the paragraph with id message is displayed. 
    $('#message').removeClass(); 
    $('#message').addClass(className); 
    $('#message').html(className + " is the current safety record."); 
}); 

});

+1

इस पूरे कोड है? यह पिछला कथन क्या है। – Sheetal

उत्तर

23

इस त्रुटि का अर्थ आप इस तरह के रूप में अपने कार्यों में से कुछ में कई var बयान, है:

var x = 1, 
    y = 2; 
+0

मैंने इसे समझ लिया। किसी कारण से JSLint प्रमाणीकरण त्रुटि यह दिखा रही थी कि त्रुटि getClassName फ़ंक्शन में थी लेकिन वास्तव में यह .click फ़ंक्शन में चर था। यह अब समझ में आता है, मुझे जेएसलिंट सत्यापन द्वारा मुझे कोड की गलत रेखा पर निर्देशित करने के लिए फेंक दिया गया था। – GMan

3
:

var x = 1; 
var y = 2; 

JSLint आप की तरह एक भी var बयान में चर घोषणाओं गठबंधन करने के लिए चाहता है

मुझे लगता है कि जेएसलिंट आपके कोड की कुछ पंक्तियों (आपके द्वारा प्रदान किए गए कोड के नीचे की ओर) का जिक्र कर रहा है:

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 

आप उन्हें एक अल्पविराम के साथ प्रत्येक चर परिसीमन से कई बार घोषित करने से बच सकते हैं:

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); 
+0

हां यह बिल्कुल है। मुझे JSLint त्रुटि द्वारा getClassName फ़ंक्शन में कोड की रेखाओं पर इशारा करते हुए फेंक दिया गया था। धन्यवाद – GMan

संबंधित मुद्दे