In: Computer Science
Your HTML document should contain the following elements/features:
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new web page with name "timerDuration.html" is created, which contains following code.
timerDuration.html:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- title for web page -->
<title>Timer Duration</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- label for Timer Duration-->
<label for="timerDuration" id="lblTimerDuration">Timer Duration</label>
<!-- textbox for timer duration -->
<input type="text" id="timerDuration" />
<br><br>
<!-- button -->
<input type="button" value="Start" id="btnStart" onclick="startTime()" />
<!-- <script> is used for javascript -->
<script>
//function startTime()
function startTime() {
//taking input entered by user
var time = parseInt(document.getElementById("timerDuration").value);
//hide the textbox
document.getElementById("timerDuration").style.display = "none";//hide textbox
document.getElementById("btnStart").style.display = "none";//hide button
document.getElementById("lblTimerDuration").style.display = "none";//hide label
//create a new paragraph
var p = document.createElement("p");
p.setAttribute("id","timerPara");//set attribute
document.body.append(p);//show paragraph
//calling function setInterval
var clear=setInterval(() => {
//if time is greater than 0
if (time >= 0) {
p.innerHTML = time;//set time
}
else {
clearInterval(clear);//clear the interval
document.getElementById("timerDuration").style.display="inline";//show textbox
document.getElementById("timerDuration").value = "";//set value in the textbox
document.getElementById("btnStart").style.display = "block";//show button
document.getElementById("lblTimerDuration").style.display = "inline";//show label
document.getElementById("lblTimerDuration").innerHTML = "New Timer";//set text
document.getElementById("timerPara").remove();//remove paragraph
}
time--;//decrement timer
}, 1000);
}
</script>
</body>
</html>
======================================================
Output : Open web page timerDuration.html in the browser and will get the screen as shown below
Screen 1 :timerDuration.html
Screen 2:Screen when timer value is entered 5
Screen 3:Screen when timer value is 0
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.