Time Converter
In this assignment, let's build a Time Converter by applying the concepts we learned till now.
Refer to the below image.
Instructions:
By following the above instructions, achieve the given functionality.
Quick Tip
Note
Use this Background image:
CSS Colors used:
Text colors Hex code values used:
#f5f7fa
#000000
#ffffff
CSS Font families used:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet">
<style>
body {
max-width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
background: url(https://assets.ccbp.in/frontend/dynamic-webapps/time-converter-bg.png) center/cover no-repeat fixed;
}
.converter-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.input-wrappers {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 20px;
}
input {
width: 25%;
padding: 8px;
outline: none;
border: 3px solid rgb(0, 0, 0);
border-radius: 5px;
background-color: rgb(209, 223, 218);
}
label {
font-size: 20px;
color: #f5f7fa;
font-weight: bold;
letter-spacing: 1.1px;
font-family: 'Open Sans', sans-serif;
}
button {
width: 30%;
padding: 8px 0;
border-radius: 15px;
font-size: 20px;
font-family: 'Open Sans', sans-serif;
background: rgb(18, 49, 92);
border: none;
color: white;
font-weight: bold;
letter-spacing: 1.2px;
margin-top: 30px;
}
button:hover {
cursor: pointer;
}
button:focus {
outline: none;
}
.seconds {
color: white;
font-size: 20px;
font-family: 'Open Sans', sans-serif;
font-weight: bold;
}
.error {
color: red;
font-size: 20px;
font-family: 'Open Sans', sans-serif;
font-weight: bold;
}
</style>
</head>
<body>
<div class="converter-wrapper">
<div class="input-wrappers">
<label for="hoursInput">Enter the number of hours:</label>
<input type="number" id="hoursInput">
</div>
<div class="input-wrappers">
<label for="minutesInput">Enter the number of minutes:</label>
<input type="number" id="minutesInput">
</div>
<button id="convertBtn" onclick="getSeconds()">Convert</button>
<p id="timeInSeconds" class="seconds"></p>
<p id="errorMsg" class="error"></p>
</div>
<script>
function getSeconds() {
var hours = parseInt(document.getElementById('hoursInput').value);
var minutes = parseInt(document.getElementById('minutesInput').value);
var seconds = (hours * 60 + minutes) * 60;
console.log(hours);
var showSeconds = document.getElementById("timeInSeconds");
var showError = document.getElementById("errorMsg");
if (isNaN(hours) || isNaN(minutes)) {
showError.textContent += "Error!!! Please enter any value"
}
else {
showSeconds.textContent = showSeconds.textContent + "the number in seconds " + seconds;
}
}
</script>
</body>
</html>
Comments
Leave a comment