I'm really lost on this assignment and javascript in general. The simpler the code the better. Any help would be a blessing

Build a combination stopwatch and countdown timer. The application will allow the user to start either a stopwatch or a countdown timer. Only one timer should be able to run at a time.

These are the minimum required options for the full application:

User option to select which type of timer to run.

Stopwatch

-Start/Stop Button that reflects current state
-Reset button to restart
-Visual indication of current time elapsed in proper time format 00:00:00
-minutes, seconds, hundredths

Countdown Timer

-User input of time to countdown in proper time format
-00:00:00
-minutes, seconds, hundredths
-validate with regex
-Start/pause button
-Some form of notification when time has elapsed to notify user
-Visual indication of current time status in proper time format 00:00:00
-minutes, seconds, hundredths
-Maximum 10 minute countdown with entry validation for range

Debug Mode

-Visual output of states
-When buttons are clicked
-Time validation entry
-Indication of when a function has been called
on/off

Therefore any time measurements would be best implemented on a millisecond basis.

The use of hundredths is going to be a bit of a problem and that is due to the inherent lag in the JavaScript interpretation process. Realistically 1/10ths is manageable but you can display a counter that updates every 1/10th of a second with the milliseconds value to look like it is counting in 1/100ths.

When using a display timer, best advice is to use the setInterval timer, each actuation of a setTimeout timer will induce some element of lag in to the program and won't be as accurate as a setInterval event timer.

Most timers are set like this, handle = setInterval("callbackFunction(),1000); and thats because 1000 is a nice tidy number when the amount should be handle = setInterval("callbackFunction(),999); because all timers start at 0 and count to 999 which is 1000 milliseconds.

You will find buried somewhere in this forum a version of a clock script that I created, mainly as an example, the format was a JSON style script like this:

the basics are simple in as far as the clock display does not need any kind of window.onload operation to start the process, this is if you like a backdoor way of making a JSON function group autonomous to needing invoking, the clock.init() function is called every 1000 milliseconds

With the use of .getMilliseconds() method, you can add to the hours minutes and seconds the number of milliseconds fairly easily however padding is a different matter.

The use of the prototype .padMilliseconds() is the simplest way I could think of to pad a number without any convoluted if(x<9) blahBlah = ... methods, however... if you are able to understand what is happening with it, you can try to explain it otherwise you would be best writing something that you know you can explain if questioned over it.

Now adding a stop watch action...

You would need to take a reference to when the clock started, subtract the current timer value from that which is stored and then display your time. The process for this is not the same as a clock with milliseconds. it involves the .getTime() method to get a time reference in milliseconds, a current time reference in milliseconds that has the initial start time deducted from it and a way of returning the time and slicing off the numbers you need and getting the milliseconds padded...

this.x = new Date(date.getTime()); //store elapsed time
//on resume get reference time and add it to the time since the stopwatch has been started
if (this.state === "resumed") date.setTime(this.snapshot.getTime() + date.getTime());

That is the wrong way of going about counting time, you already have a suite of methods and access to the system timer and event timers as demonstrated, why spend time adding and padding when you can be getting and slicing out of a time string what you need?

In my example the only padding needed was on the milliseconds, the rest of the timer functions were based on the Date object and getting accurate system times, using event timers to run functions at set intervals to update a display rather than a cumbersome method of using counters and testing them to see if they are in or out of range.

12-17-2013, 11:44 PM

6SIX

This is really the 11th hour of my class. I still don't understand how to do much of anything. This is the regex I tried to adapt from a previous assignment on phone numbers.

I am not a regex person, for something that professes to be "Regular" expressions, it is anything but regular.

Code:

var regex = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;

This will do the job to a degree in as far as it will allow 11/12/2013 but also will allow 99/01/1212 but not allow 1/1/2014 because it is looking for a prefix of 0 to single digits.

In short, this is [0-9]{2} allows any number 00 to 99 the {2} indicates 2 digits if you want to allow single digits you need to indicate this with {1,2} in english it will allow 1 of 2 digits.

Code:

var regex = /^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/;

that allows 1/1/2014, etc.

12-18-2013, 12:17 PM

\\.\

Also note that dates are DD / MM / YYYY format not MM / DD / YYYY that MM / DD / YYYY is not an ISO standard date which you should be programming to in the world of computers and your tutor should be shot for it and please feel free to quote me on that.

12-18-2013, 09:40 PM

6SIX

Quote:

Originally Posted by \\.\

Also note that dates are DD / MM / YYYY format not MM / DD / YYYY that MM / DD / YYYY is not an ISO standard date which you should be programming to in the world of computers and your tutor should be shot for it and please feel free to quote me on that.

This guy doesn't care about standards. He just wants what is required for the assignment. Real world applications will get 0 credit.

12-19-2013, 02:09 AM

\\.\

WTF is wrong with the guy?

How can he claim to be teaching a class in a standard that does not exist beyond the class room?

IMHO the education board need to be informed of his rigid uncompromising attitudes, educators are supposed to encourage individualism, he / she sounds more like a totalitarian dictator.

If you are to conform to that method then you need to adapt the Reg Expression and also any scripts because it is normal to expect a DD MM YYYY format.

Code:

var regex = /^[0-1]{0,1}[0-9]{1}\/[0-3]{0,1}[0-9]{1}\/[0-9]{4}$/;

is in the MM DD YYYY format and more specifically you are limited to inputting a date beginning 0 or 1 and 0 to 9 which means you can't input 99 but could input 19 for months. Code does exist as a RegEx that would check that you could only enter 1 to 12 I would suggest a second RegEx for a 2nd pass check to ensure that any date references can't begin for example 19/39/****

Like I said, I am not really a RegExp person, they really do irritate the hell out of me, if I really wanted to learn about hieroglyphics then I would have taken ancient history and languages.