var idinterval;
var second_input_value = document.getElementById("Seconds");
var minute_input_value = document.getElementById("Minutes");
var second_val = second_input_value.value;
var minute_val = minute_input_value.value;
var total_time = parseInt(minute_val * 60) + parseInt(second_val);
function starter() {
if (total_time > 0) {
total_time = total_time - 1;
document.getElementById("timing").innerHTML = Math.floor(total_time / 60) + ":" + total_time % 60;
return;
}
}
function start_the_clock() {
setInterval(() => {
starter();
}, 1000);
}
::placeholder {
font-size: 20px;
}
.ClockStart {
color: white;
width: 120px;
height: 37px;
padding: 6px;
font-size: 15px;
background-color: rgb(21, 27, 84);
margin-top: 30px;
margin-right: 5px;
}
.ClockStart:hover {
background-color: #0000B9;
}
.ClockPause {
color: white;
width: 120px;
height: 37px;
padding: 6px;
font-size: 15px;
background-color: #767676;
margin-top: 30px;
margin-right: 5px;
}
.ClockPause:hover {
background-color: #444444;
}
.ClockStop {
color: white;
width: 120px;
height: 37px;
padding: 6px;
font-size: 15px;
background-color: #B2B2B2;
margin-top: 30px;
margin-right: 5px
}
.ClockStop:hover {
background-color: #303030;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="timer.css" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timekeeper</title>
</head>
<body>
<script src="timer.js" type="text/javascript"></script>
<div style="margin-top:50px;margin-left:50px;">
<h1 style="font-size: 60px; color: black;font-weight: bold;">Timekeeper</h1>
<hr style="transform: rotate(90deg);margin-left:350px;width:200px ">
<form id="timer_form">
<label style="font-size: 30px; font-weight:100; font-style: italic; margin-bottom: 500px;width:5px">
Minutes <input id="Minutes" value="0" placeholder="00" style="font-size:20px;background-color:transparent;margin-left: 10px; color:black;height:30px; width: 200px;border-top: none;border-left: none;border-right: none;border-bottom: 1px solid black;" type="number" min="1 " max="2000000">
</label>
<br><br>
<label style="font-size: 30px; font-weight:100; font-style: italic; margin-top: 100px ;">
Seconds
<input id="Seconds" placeholder="00" value="0" style="font-size:20px;background-color:transparent;margin-left: 10px; color:black;height:30px; width: 200px;border-top: none;border-left: none;border-right: none;border-bottom: 1px solid black;" type="number" min="1 " max="2000000">
</label></form>
<br>
<button class="ClockStart" id="start" type="button" onclick="start_the_clock()">Start</button>
<button class="ClockPause" id="pause" type="button" onclick="stop()">Pause</button>
<button class="ClockStop" id="stop" type="button" onclick="reset()">Stop</button>
<p id="timing" style="font-weight: 600;font-size:100px; position:relative; bottom:300px; left:500px;">00:00</p>
</div>
</body>
</html>
Note: this is a basic function for keeping time where the user provides minutes and seconds as input in an HTML form ,this is the issue reported by the browser console after running the code
Could someone help me troubleshoot the problem?
Uncaught TypeError: second_input is null
Note: The error occurs only in the JavaScript portion of the code. When I tried changing the values of minute_input and second_input to integers, it worked fine