WebDevelopAssign
WebDevelopAssign
<!DOCTYPE html>
<html>
<head>
background-
</style>
</head>
<body>
<button id="red">Red</button>
<button id="green">Green</button>
<button id="blue">Blue</button>
<button id="random">Random</button>
document.getElementById('heading'); constredButton =
document.getElementById('red'); constgreenButton =
document.getElementById('green'); constblueButton =
document.getElementById('blue'); constrandomButton =
document.getElementById('random');
heading.style.color = 'white';
1
});
= 'green'; heading.style.color
= 'black';
});
= 'blue'; heading.style.color
= 'white';
});
document.body.style.backgroundColor = randomColor;
});
color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/).slice(1).map(Number); return
</script>
2
</body>
</html>
Output :-
2. Write a program in JS to take string as input from user and then display the same string.
<!DOCTYPE html>
<html>
<head>
3
<title>String Input and Output</title>
</head>
<body>
<p id="output"></p>
document.getElementById("userInput").value;
</script>
</body>
</html>
Output : -
<html>
<head>
<title>Simple Calculator</title>
<style>
body { font-family:
Arial, sans-serif;
}
4
#calculator { width: 200px; margin:
20px;
#display {
width: 100%;
height: 40px;
10px;
right;
}
.button {
width: 40px;
height: 40px;
margin: 5px;
padding: 10px;
border: none;
border-radius:
10px; font-
size: 18px;
cursor: pointer;
}
.button:hover {
background-color: #ccc;
}
</head>
<body>
<div id="calculator">
<div>
class="button" onclick="press('9')">9</button>
</div>
<div>
class="button" onclick="press('6')">6</button>
</div>
<div>
</div>
<div>
class="button" onclick="press('=')">=</button>
</div>
document.getElementById('display'); {
function clearDisplay() {
= '';
}
</script>
</body>
</html>
Output :-
4. Write a JavaScript function called “Second Largest” that accepts an array of integers as
parameter and displays the second largest element in the array. Test the function with different
inputs. Embed the JavaScript function within the HTML document.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
// JavaScript function to find the second largest element in an array function
secondLargest() {
// Get the input value from the text box const input =
document.getElementById("inputArray").value;
// Check if the array has enough elements to find the second largest
if (arr.length< 2) {
secondLargest = -Infinity;
// Loop through the array to find the first and second largest for
= arr[i];
} else if (arr[i] >secondLargest&&arr[i] !== firstLargest) { secondLargest
= arr[i];
// If the second largest element is still -Infinity, there's no distinct second largest if (secondLargest
} else {
</script>
</head>
<body>
</body>
</html>
Output : -
5. Develop a web page and demonstrate event handling mechanisms- with the click button a
message is displayed. Use JS function for handling the events.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Handling Example</title>
<script> function
displayMessage() { alert("Hello! You
clicked the button.");
}
</script>
</head>
<body>
<h2>Event Handling Example</h2>
<p>Click the button below to see the message:</p>
<button onclick="displayMessage()">Click Me!</button>
</body>
</html>
Output :-
/* Button styling */
button { padding: 10px 20px;
border-radius: 5px;
background-color: #007BFF;
button:hover { background-
color: #0056b3;
}
</style>
</head>
<body>
<!-- Inline CSS for the header -->
<h1 style="font-size: 2.5rem; color: white; background-color: #333; padding: 10px; text-align:
center;">
CSS Styling Example
</h1>
<!-- Paragraph --> <p>
This is a paragraph styled using internal CSS to demonstrate text alignment and font family.
</p>
background-image: url("https://img.freepik.com/free-photo/anime-moon-
landscape_232151645903.jpg?t=st=1733473626~exp=1733477226~hmac=ed813a34369df5d0a
c
8bb2074398 c4b2abf6ed72fb06ce51df90405f96f7f994&w=996"); /* Add a background image
*/ background-size: cover; /* Ensure the background covers the div */ color: white; box-
shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Add shadow for depth */ width: 50%; /* Set the width to
80% of the viewport or container */ height: 340px; /* Set the height of the div */ margin:
0 auto; /* Center the div horizontally */ text-align: center; /* Center-align text inside the div
*/
}
/* Styling for the unordered list */
ul {
list-style-type: square; /* Change bullet style to square */ margin:
20px 0; /* Add vertical spacing */ padding-left:
20px; /* Add indentation */
} ul li
{
}
Output : -