Web Programming Lab report 02
Web Programming Lab report 02
Lab Report NO # 02
Course Title: Web Programming Lab
Course Code: CSE 302 Section: D21
Name ID
2. OBJECTIVES
<script>
function convertctof() {
var celsius = parseFloat(document.getElementById("cinput").value);
var fahrenheit = (celsius * 9/5) + 32;
document.getElementById("rf").innerHTML = celsius + "°Celsius is " +
fahrenheit.toFixed(2) + "°F.";
}
function converttoc() {
var fahrenheit = parseFloat(document.getElementById("finput").value);
var celsius = (fahrenheit - 32) * 5/9;
document.getElementById("rc").innerHTML = fahrenheit + "°Fahrenheit is " +
celsius.toFixed(2) + "°C.";
}
</script>
</body>
</html>
Explain: Create a text filed where user input the Celsius and create a onclick button while
user click the button there shows the result and the other convert to Celsius also work same.
In JavaScript function defines a JavaScript function to convert Celsius to Fahrenheit. It retrieves
the Celsius temperature entered by the user, performs the conversion formula, and updates the
HTML to display the result. And other function Fahrenheit to Celsius work in same way.
Output:
<html>
<head>
<title>Nur Hasan Hasib</title>
</head>
<body>
<h2>Input Determiner</h2>
<p>Input a value:</p>
<input type="text" id="inputValue">
<button onclick="dtype()">Determine Type</button>
<p id="result"></p>
<script>
function dtype() {
var value = document.getElementById("inputValue").value;
var result = document.getElementById("result");
if (!isNaN(value)) {
result.textContent = value > 0 ? value + " positive number." : value < 0 ?
value + " negative number." : "intput zero.";
} else if (value.length === 1) {
result.textContent = value === value.toUpperCase() ? value + " uppercase
character." : value === value.toLowerCase() ? value + " lowercase character." :
"input is not upper and lower char";
} else {
result.textContent = "Invalid input.";
}
}
</script>
</body>
</html>
Explain: The user enters a value in the input field. When the "Determine Type" button is
clicked, the dtype() function is called. This function checks if the input is a number using is
Nan ().If it's a number, it determines whether it's positive, negative, or zero. If it's not a
number and its length is 1, it checks if it's an uppercase or lowercase character. Finally, it
updates the HTML to display the result.
Output:
Explain: The user can input a character into the text field and clicking the "Check" button, the
checkc() function is called.The function converts the input character to lowercase to ensure
uniformity.It then uses a switch statement to check the character against the vowels ('a', 'e', 'i', 'o',
'u').If the character matches any of the vowels, it displays a message indicating that it's a vowel.
If the character doesn't match any of the vowels, it's considered a consonant, and a corresponding
message is displayed
Output:
Task 04: Calculate sum of even numbers up to 100 using for loop
Code:
<html>
<head>
<title>NUR HASAN HASIB</title>
</head>
<body>
<h1>sum of even num of 100</h1>
<p id="r"></p>
<script>
var s = 0;
for (var i = 0; i <= 100; i += 2) {
s+= i;
}
document.getElementById("r").textContent = "sum even num of 100: " + s;
</script>
</body>
</html>
Explain: It initializes a variable s to store the sum. It uses a for loop to iterate from 0 to 100 with a
step of 2, considering only even numbers. Inside the loop, it adds each even number to the s. Finally, it
displays the result in the paragraph element with the id "r".
Output: