DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

Declare javascript function, jQuery

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?

Upvotes: 2

Views: 1124

Answers (3)

xil3
xil3

Reputation: 16439

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;

Upvotes: 1

46bit
46bit

Reputation: 1537

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;
}

Upvotes: 2

Matti Virkkunen
Matti Virkkunen

Reputation: 65116

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.

Upvotes: 1

Related Questions