Time Converter:
Instructions:
By following the above instructions, achieve the given functionality.
Quick Tip
Note
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<label>
<span>Hours:</span>
<input type="text" id="hoursInput">
</label>
<label>
<span>Minutes:</span>
<input type="text" id="minutesInput">
</label>
<button type="button" id="convertBtn">Convert to seconds</button>
<p id="timeInSeconds"></p>
<p id="errorMsg"></p>
</div>
<script>
let btnConvert = document.getElementById('convertBtn');
btnConvert.addEventListener('click', function() {
let hours = +document.getElementById('hoursInput').value;
let minutes = +document.getElementById('minutesInput').value;
let resultBox = document.getElementById('timeInSeconds');
let errorBox = document.getElementById('errorMsg');
errorBox.innerText = '';
resultBox.innerText = '';
if (hours && minutes) {
resultBox.innerText = `Result after convert: ${ Math.floor( (hours * 60 + minutes) * 60 ) } seconds`;
} else {
errorBox.innerText = 'Error! Enter positive integer number values hours or minutes';
}
});
</script>
</body>
</html>
Comments
Leave a comment