Skip to main content
Update wording
Source Link

Looks pretty good! Here'sHere are a couple of pointers for you:

It's custom to declare jQuery variables with a $ prefix. This way it's easy to tell at a glance that it is a element collection. So your top variables would look like this:

var $secondsDiv = $("#seconds");
var $minsDiv = $("#mins");

Instead of:

if (timer===false)

Consider:

if (!timer)

If you're looking for legibility there are probably a few other things I'd do differently.

Grouping your variables allows you to make a few shortcuts:

var time = {
  seconds: $("#seconds"), 
  minutes: $("#mins"),
  hours:   $("#hours")
}

function getValue(timeStr) {
  return time[timeStr].html();
}

getValue('seconds')

And I'm not sure about the check59() implementation. I'm sure we could make that more efficient, and reduce the repetition.

But the next step for you is definitely to create a class for this and scope your variables, that way you'll be able to include multiple timers in the same page :)

Looks pretty good! Here's a couple of pointers for you:

It's custom to declare jQuery variables with a $ prefix. This way it's easy to tell at a glance that it is a element collection. So your top variables would look like this:

var $secondsDiv = $("#seconds");
var $minsDiv = $("#mins");

Instead of:

if (timer===false)

Consider:

if (!timer)

If you're looking for legibility there are probably a few other things I'd do differently.

Grouping your variables allows you to make a few shortcuts:

var time = {
  seconds: $("#seconds"), 
  minutes: $("#mins"),
  hours:   $("#hours")
}

function getValue(timeStr) {
  return time[timeStr].html();
}

getValue('seconds')

And I'm not sure about the check59() implementation. I'm sure we could make that more efficient, and reduce the repetition.

But the next step for you is definitely to create a class for this and scope your variables, that way you'll be able to include multiple timers in the same page :)

Looks pretty good! Here are a couple of pointers for you:

It's custom to declare jQuery variables with a $ prefix. This way it's easy to tell at a glance that it is a element collection. So your top variables would look like this:

var $secondsDiv = $("#seconds");
var $minsDiv = $("#mins");

Instead of:

if (timer===false)

Consider:

if (!timer)

If you're looking for legibility there are probably a few other things I'd do differently.

Grouping your variables allows you to make a few shortcuts:

var time = {
  seconds: $("#seconds"), 
  minutes: $("#mins"),
  hours:   $("#hours")
}

function getValue(timeStr) {
  return time[timeStr].html();
}

getValue('seconds')

And I'm not sure about the check59() implementation. I'm sure we could make that more efficient, and reduce the repetition.

But the next step for you is definitely to create a class for this and scope your variables, that way you'll be able to include multiple timers in the same page :)

Source Link
Jivings
  • 2.3k
  • 14
  • 17

Looks pretty good! Here's a couple of pointers for you:

It's custom to declare jQuery variables with a $ prefix. This way it's easy to tell at a glance that it is a element collection. So your top variables would look like this:

var $secondsDiv = $("#seconds");
var $minsDiv = $("#mins");

Instead of:

if (timer===false)

Consider:

if (!timer)

If you're looking for legibility there are probably a few other things I'd do differently.

Grouping your variables allows you to make a few shortcuts:

var time = {
  seconds: $("#seconds"), 
  minutes: $("#mins"),
  hours:   $("#hours")
}

function getValue(timeStr) {
  return time[timeStr].html();
}

getValue('seconds')

And I'm not sure about the check59() implementation. I'm sure we could make that more efficient, and reduce the repetition.

But the next step for you is definitely to create a class for this and scope your variables, that way you'll be able to include multiple timers in the same page :)