In: Computer Science
Instructions
Submission Guidelines
This assignment may be submitted for full credit until Friday, October 4th at 11:59pm. Late submissions will be accepted for one week past the regular submission deadline but will receive a 20pt penalty. Submit your work as a single HTML file. It is strongly recommended to submit your assignment early, in case problems arise with the submission process.
Assignment
For this assignment, you will write a timer application in HTML and JavaScript.
Your HTML document should contain the following elements/features:
Evaluation
Your assignment will be graded according to whether all the required elements are present and in the correct formats and all required functionalities are operable.
<!DOCTYPE html>
<html>
<head>
<title>Count Down Timer</title>
</head>
<body>
<!--(a) and (b) Input for seconds to start with -->
<div id="inputTime">
<input value='0' id="time"> <!--(a)-->
<button onclick="start()">Start</button> <!--(b)-->
</div>
<!-------------------------------------- -->
<!--(c)--->
<p id="display">
</p>
<!--------->
<!--(e) and (f)-->
<div style="display: none" id="newT">
<button onclick="newTimer()">New Timer</button>
</div>
<!--------------->
</body>
<script>
function start(){
document.getElementById("inputTime").style.display="none"; //On start input element and button is removed
var time=document.getElementById("time").value; //Initializing time to the given input value
document.getElementById("display").style.display="block"; //Making the <p> tag visible
document.getElementById("display").innerHTML = time + " seconds remaining";
var timer = setInterval(function(){
time -= 1; //Time is decreased by for each 1 second
document.getElementById("display").innerHTML = time + " seconds remaining"; //Display of time remaining
if(time <= 0){
document.getElementById('newT').style.display="block";
document.getElementById("display").style.display="none";
document.getElementById("time").value=0;
clearInterval(timer);
}
}, 1000);
}
function newTimer(){ //newTimer() function
document.getElementById("inputTime").style.display="block";
document.getElementById('newT').style.display="none";
}
</script>
</html>