Jump to content

Recommended Posts

I'm a noob when it comes to JS, but every example I've seen for a looping function looks the same but when I do it I get 'startTime is not defined'.

 

here's the function: (it's inside a jquery ready function, so it doesn't start till everything is loaded)

var colon = 0;
function startTime(){
	var today = new Date();
	var hours = today.getHours();
	var mins = today.getMinutes();
	var monthdate = today.getDate();
	var ampm = 'am';
	if(hours>11){
		ampm = 'pm';
	}
	if(mins<10){
		mins = '0'+mins;
	}
	$('#the_date').text(monthdate);
	$('#the_time_h').text(hours);
	$('#the_time_m').text(mins);
	$('#the_time_ampm').text(ampm);
	if(colon == 0){			
		$('#the_time_colon').css('visibility','hidden');
		colon = 1;
	}else{
		$('#the_time_colon').css('visibility','visible');
		colon = 0;
	}

	//month
	var month = today.getMonth();
  	var months = new Array(13);
	months[0]  = "January";
	months[1]  = "February";
	months[2]  = "March";
	months[3]  = "April";
	months[4]  = "May";
	months[5]  = "June";
	months[6]  = "July";
	months[7]  = "August";
	months[8]  = "September";
	months[9]  = "October";
	months[10] = "November";
	months[11] = "December";

	$('#month p').text(months[month]);
	$('#month p').addClass(months[month].toLowerCase());
	timer=setTimeout("startTime()",500);
}
startTime();

 

Thx for any and all help.

Justin

Link to comment
https://forums.phpfreaks.com/topic/196379-looping-function/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.