Uploaded by Asif K

LAB PGM 9 & 10

advertisement
LAB PROGRAM 9
<html>
<head>
<title>Get date and time in JavaScript.</title>
</head>
<body>
<h2>Get date and time using JavaScript.</h2>
<h4>Output after using the basic methods of the Date() class.</h4>
<div id="date"> </div>
<div id="time"> </div>
<script type="text/javascript">
let date = document.getElementById("date");
let time = document.getElementById("time");
// creating the date object and getting the date and time
let newDate = new Date();
let year = newDate.getFullYear();
let month = newDate.getMonth()+1;
let todaySDate = newDate.getDate();
let hours = newDate.getHours();
let minutes = newDate.getMinutes();
let seconds = newDate.getSeconds();
date.innerHTML = " " + todaySDate + "/ " + month + "/ " + year;
time.innerHTML = hours + ": " + minutes + ": " + seconds;
</script>
</body>
</html>
LAB PROGRAM 10
<html>
<body>
<div class="container">
<h1>
Temperature Converter</h1>
<div class="converter-row">
<div class="col">
<label>Fahrenheit</label>
<input type="number" id="fahrenheit">
</div>
<div class="col">
<label>Celsius</label>
<input type="number" id="celsius">
</div>
</div>
</div>
<script>
let celsius = document.getElementById('celsius');
let fahrenheit = document.getElementById('fahrenheit');
celsius.oninput = function () {
let f = (parseFloat(celsius.value) * 9) / 5 + 32;
fahrenheit.value = parseFloat(f.toFixed(2));
}
fahrenheit.oninput = function () {
let c = ((parseFloat(
fahrenheit.value) - 32) * 5) / 9;
celsius.value = parseFloat(c.toFixed(2));
}
</script>
</body>
</html>
Download