I noticed a few other problems with your code, I've commented the fixes and added a couple of other tips too.
var seconds = 0;
var clockId;
var correctAns;
// Lets get a reference to the quizclock element and save it in
// a variable named quizclock
var quizclock = document.getElementById('quizclock');
function runClock() {
// seconds + 1;
// This calculates seconds + 1 and then throws it away,
// you need to save it back in to the variable
// You could do that with:
// seconds = seconds + 1;
// But it would be even better with the shorthand:
seconds += 1;
// set the HTML inside of the quizclock element to new time
quizclock.innerHTML = seconds;
}
function startClock() {
showQuiz();
runClock();
// setInterval("runClock()", 1000);
// When using setInterval and setTimeout you generally just
// want to directly pass it the function by name. Passing it
// a string "runClock()" is in effect actually running
// eval("runClock()"), eval should be avoided unless you
// really need it.
// setInterval returns a number which identifies the interval,
// you need to save that number, you'll need it when you
// call clearInterval
clockId = setInterval(runClock, 1000);
}
function stopClock() {
// clearInterval takes the id that setInterval
// returned to clear the interval
clearInterval(clockId);
gradeQuiz();
// you had this alert statment after the return statement,
// it would have never run, return statements end the
// function and anything after them is ignored
alert("You have " + correctAns + " correct out of 5 in " +
quizclock + " seconds.");
//return = correctAns;
// the return statement doesn't need a =,
// return = correctAns says set a variable named return to the
// value of correctAns since return is a reserved word,
// that should generate an error
return correctAns;
}
Some useful reference links:
If this is for a formal class you might have to just use basic DOM methods to get elements (getElementById, etc). If you are just learning on your own I would encourage you to learn a DOM library. I would suggest jQuery, it is easy to learn and is now more or less the de facto standard. With jQuery instead of document.getElementById('quizclock') you could just do this: $('#quizclock'). Using jQuery makes your code a little shorter, standardizes things between different browsers and helps protect you from bugs in those browsers.
You are just a beginner now, in small examples like this you don't need to worry about global variables, but you should know that it is generally a bad idea to use too many of them. What if another function on the page also used a global variable named seconds? It might change seconds and screw up your timer. This is getting a little advance, but one way to avoid this is to wrap your code in a self-invoking anonymous function:
(function () {
var seconds = 0;
// inside here seconds is visible and can be used
}());
// outside seconds is not declared, it will return undefined.
Unfortunately any functions inside will also not be visible on the outside, so attaching them via onclick= wouldn't work but you could (should) attach them in using the DOM:
var submitButton = document.getElementById('submitanswers'); // you'll have to give the button an id
submitButton.addEventListener('click', stopClock, false);
Again, using jQuery would make this even easier:
$('#submitanswers').on('click', stopClock);
Likewise if you use jQuery, it already forces you to wrap your code in a function which will keep your variables out of the globalnamespace:
$(document).ready(function () {
var seconds;
// again seconds is visible here
});
// but not here