views:

45

answers:

3

Hi,

in my main js file where I put all my jQuery stuff I have following new funcitons:

function getDate(){
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    return  day"."+month+"."+year;
}

function getTime(){
    var currentTime = new Date();
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();
    if (minutes < 10){
        minutes = "0" + minutes;
    }

    return  hours":"+minutes;
}

...but when I have these functions added to my main js file the jquery part does not work anymore. any ideas?

+1  A: 

Missing a +:

return  day"."+month+"."+year;

Here as well:

return  hours":"+minutes;

Syntax errors will prevent the entire file from being executed. You should really look at your browser's error console before posting.

Matti Virkkunen
+2  A: 

Well for starters, you were concatenating strings wrongly.

function getDate(){
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    return day + "." + month + "." + year;
}

function getTime(){
    var currentTime = new Date();
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();
    if (minutes < 10){
        minutes = "0" + minutes;
    }

    return hours + ":" + minutes;
}
46Bit
+1  A: 

It probably breaks it because of a syntax error in your functions:

You are missing the '+' in both your returns after 'day' and 'hours'.

return  day"."+month+"."+year; 

should be

return  day+"."+month+"."+year;

and

return  hours":"+minutes;

should be

return  hours+":"+minutes;
xil3