If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Homework Assignment Help!

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...

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.

--> JavaScript Frameworks like JQuery, Angular, Node <--
... and please remember to wrap code with forum BBCode tags:- [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]If you can't think outside the box, you will be trapped forever with no escape...

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.

--> JavaScript Frameworks like JQuery, Angular, Node <--
... and please remember to wrap code with forum BBCode tags:- [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]If you can't think outside the box, you will be trapped forever with no escape...

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.

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.

--> JavaScript Frameworks like JQuery, Angular, Node <--
... and please remember to wrap code with forum BBCode tags:- [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]If you can't think outside the box, you will be trapped forever with no escape...