Timing a test

I want to create a test that allows only 30 minutes for students to complete. Three minutes before the test expires, the webpage must display a message alerting the student that they have only 3 minutes left to complete the quiz. If the student does not submit the test before the 30 minutes are up, the student gets a 0. How do I do this with Javascript?