Css Pr Answers
Css Pr Answers
<!DOCTYPE html><html><head>
<title>Image Rollover Effect</title></head><body>
<img id="rolloverImage" src="image1.jpg" alt="Image"
onmouseover="changeImage('image2.jpg')"
onmouseout="changeImage('image1.jpg')"
style="width: 300px; height: 200px;">
<script>
function changeImage(newSrc) {
var img = document.getElementById('rolloverImage');
img.src = newSrc;
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Slideshow</title></head><body>
<img id="slideshow" src="image1.jpg" alt="Slideshow" style="width: 400px; height: 300px;">
<button onclick="startSlideshow()">Start</button>
<button onclick="stopSlideshow()">Stop</button>
<script>
var images = ['image1.jpg', 'image2.jpg', 'image3.jpg'];
var index = 0;
var interval;
function startSlideshow() {
interval = setInterval(function() {
index = (index + 1) % images.length;
document.getElementById('slideshow').src = images[index];
}, 2000);
}
function stopSlideshow() {
clearInterval(interval);
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Fruits Array</title></head><body>
<button onclick="showFruits()">Show Fruits</button>
<script>
function showFruits() {
var Fruits = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
alert('Fruits: ' + Fruits.join(', '));
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Palindrome Checker</title></head><body>
<input type="text" id="inputString" placeholder="Enter a string">
<button onclick="checkPalindrome()">Check Palindrome</button>
<script>
function checkPalindrome() {
var str = document.getElementById('inputString').value;
var reversedStr = str.split('').reverse().join('');
if (str === reversedStr) {
alert('It is a palindrome!');
} else {
alert('Not a palindrome.');
}
}
</script></body></html>
5.Write a function that prompts the user for a color and uses what they
select to set the background color of the new webpage opened
<!DOCTYPE html><html><head>
<title>Change Background Color</title></head><body>
<button onclick="changeBackgroundColor()">Change Background</button>
<script>
function changeBackgroundColor() {
var color = prompt('Enter a color for the background:');
var newWindow = window.open('', '', 'width=400,height=400');
newWindow.document.body.style.backgroundColor = color;
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>College Admission Form</title></head><body>
<h1>College Admission Form</h1>
<form action="#" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob" required><br><br>
<label for="course">Select Course:</label>
<select id="course" name="course">
<option value="B.Tech">B.Tech</option>
<option value="B.Sc">B.Sc</option>
<option value="B.Com">B.Com</option>
</select><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<input type="submit" value="Submit">
</form></body></html>
7. Write a Java script that will replace following specified value with
another value in a string. String = “ I will fail” Replace “fail” by “pass”
<!DOCTYPE html><html><head>
<title>Replace String Value</title></head><body>
<button onclick="replaceValue()">Replace Value</button>
<script>
function replaceValue() {
var str = "I will fail";
var newStr = str.replace("fail", "pass");
alert("Original: " + str + "\nUpdated: " + newStr);
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Rotating Banner Ads</title></head><body>
<a id="bannerLink" href="#" target="_blank">
<img id="banner" src="ad1.jpg" alt="Banner Ad" style="width: 400px; height: 150px;">
</a>
<script>
var banners = [
{ image: "ad1.jpg", url: "https://www.google.com" },
{ image: "ad2.jpg", url: "https://www.msbte.org" },
{ image: "ad3.jpg", url: "https://www.yahoo.com" }
];
var index = 0;
function rotateBanner() {
index = (index + 1) % banners.length;
document.getElementById("banner").src = banners[index].image;
document.getElementById("bannerLink").href = banners[index].url;
}
setInterval(rotateBanner, 3000);
</script></body></html>
9. Create a slideshow with the group of four images, also simulate the
next and previous transition between slides in your JavaScript
<!DOCTYPE html><html><head>
<title>Slideshow with Navigation</title></head><body>
<img id="slideshow" src="img1.jpg" alt="Slideshow" style="width: 400px; height: 300px;">
<br>
<button onclick="previousSlide()">Previous</button>
<button onclick="nextSlide()">Next</button>
<script>
var images = ['img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg'];
var index = 0;
function showSlide() {
document.getElementById('slideshow').src = images[index];
}
function nextSlide() {
index = (index + 1) % images.length;
showSlide();
}
function previousSlide() {
index = (index - 1 + images.length) % images.length;
showSlide();
}
</script></body></html>
10. Write a Javascript to create a pull – down menu with three options
[Google, MSBTE, Yahoo] once the user will select one of the options
then user will be redirected to that site.
<!DOCTYPE html><html><head>
<title>Pull-Down Menu Redirect</title></head><body>
<select id="menu" onchange="redirect()">
<option value="">Select an option</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.msbte.org">MSBTE</option>
<option value="https://www.yahoo.com">Yahoo</option>
</select>
<script>
function redirect() {
var url = document.getElementById('menu').value;
if (url) {
window.location.href = url;
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>First 20 Even Numbers</title></head><body>
<h3>First 20 Even Numbers:</h3>
<script>
document.write('<ul>');
for (var i = 1; i <= 20; i++) {
document.write('<li>' + (i * 2) + '</li>');
}
document.write('</ul>');
</script></body></html>
<!DOCTYPE html><html><head>
<title>Array Operations</title></head><body>
<button onclick="arrayOperations()">Perform Array Operations</button>
<script>
function arrayOperations() {
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
alert('Original Array: ' + arr.join(', '));
<!DOCTYPE html><html><head>
<title>Factorial Calculator</title></head><body>
<input type="number" id="num" placeholder="Enter a number">
<button onclick="calculateFactorial()">Calculate Factorial</button>
<script>
function calculateFactorial() {
var num = parseInt(document.getElementById('num').value);
if (num < 0) {
alert('Factorial is not defined for negative numbers.');
return;
}
var factorial = 1;
for (var i = 1; i <= num; i++) {
factorial *= i;
}
alert('The factorial of ' + num + ' is ' + factorial);
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Factorial Using Recursion</title></head><body>
<input type="number" id="recNum" placeholder="Enter a number">
<button onclick="factorialRec()">Calculate Factorial</button>
<script>
function factorial(num) {
if (num === 0 || num === 1) return 1;
return num * factorial(num - 1);
}
function factorialRec() {
var num = parseInt(document.getElementById('recNum').value);
if (num < 0) {
alert('Factorial is not defined for negative numbers.');
return;
}
alert('The factorial of ' + num + ' is ' + factorial(num));
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Even or Odd Checker</title></head><body>
<input type="number" id="number" placeholder="Enter a number">
<button onclick="checkEvenOdd()">Check Even or Odd</button>
<script>
function checkEvenOdd() {
var num = parseInt(document.getElementById('number').value);
if (num % 2 === 0) {
alert(num + ' is Even');
} else {
alert(num + ' is Odd');
}
}
</script></body></html>
16. Write Javascript to create cookie of user’s name and display it.
<!DOCTYPE html><html><head>
<title>Create and Display Cookie</title></head><body>
<input type="text" id="userName" placeholder="Enter your name">
<button onclick="createCookie()">Create Cookie</button>
<button onclick="displayCookie()">Display Cookie</button>
<script>
function createCookie() {
var name = document.getElementById('userName').value;
if (name) {
document.cookie = "userName=" + name + ";path=/;";
alert('Cookie created!');
} else {
alert('Please enter a name!');
}
}
function displayCookie() {
var cookies = document.cookie.split('; ');
for (var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
if (parts[0] === 'userName') {
alert('User Name from Cookie: ' + parts[1]);
return;
}
}
alert('No cookie found!');
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Open New Window</title></head><body>
<button onclick="openNewWindow()">Open Google</button>
<script>
function openNewWindow() {
window.open("https://www.google.com", "_blank", "width=800,height=600");
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>String Case Conversion</title></head><body>
<input type="text" id="inputString" placeholder="Enter a string">
<button onclick="convertCase()">Convert Case</button>
<script>
function convertCase() {
var str = document.getElementById('inputString').value;
if (str) {
alert("Uppercase: " + str.toUpperCase() + "\nLowercase: " + str.toLowerCase());
} else {
alert('Please enter a string!');
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Person Object</title></head><body>
<button onclick="displayPerson()">Display Person Details</button>
<script>
function displayPerson() {
var person = {
name: "John Doe",
age: 30,
address: "123 Main Street, Cityville"
};
alert("Name: " + person.name + "\nAge: " + person.age + "\nAddress: " + person.address);
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Reverse String</title></head><body>
<input type="text" id="stringToReverse" placeholder="Enter a string">
<button onclick="reverseString()">Reverse String</button>
<script>
function reverseString() {
var str = document.getElementById('stringToReverse').value;
if (str) {
var reversed = str.split('').reverse().join('');
alert("Original: " + str + "\nReversed: " + reversed);
} else {
alert('Please enter a string!');
}
}
</script></body></html>
<script>
function openMultipleWindows() {
window.open("https://www.google.com", "_blank", "width=800,height=600");
window.open("https://www.yahoo.com", "_blank", "width=800,height=600");
window.open("https://www.bing.com", "_blank", "width=800,height=600");
}
</script></body></html>
24. Write javascritp to create persistent cookie with name location and
value Nashik.
<!DOCTYPE html><html><head>
<title>Create Persistent Cookie</title></head><body>
<button onclick="createPersistentCookie()">Create Persistent Cookie</button>
<button onclick="displayCookie()">Display Cookie</button>
<script>
function createPersistentCookie() {
var expiryDate = new Date();
expiryDate.setFullYear(expiryDate.getFullYear() + 1); // Set expiration to 1 year from now
document.cookie = "location=Nashik;expires=" + expiryDate.toUTCString() + ";path=/;";
alert("Persistent cookie created!");
}
function displayCookie() {
var cookies = document.cookie.split('; ');
for (var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
if (parts[0] === 'location') {
alert("Cookie Value: " + parts[1]);
return;
}
}
alert("No cookie found!");
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Array Functions</title></head><body>
<button onclick="demonstrateArrayFunctions()">Demonstrate Array Functions</button>
<script>
function demonstrateArrayFunctions() {
var arr = [10, 20, 30, 40, 50];
alert("Original Array: " + arr);
// slice
var sliced = arr.slice(1, 4);
alert("Sliced Array (1, 4): " + sliced);
// splice
arr.splice(2, 1, 99, 100);
alert("After Splice (remove 1 at index 2, add 99, 100): " + arr);
// push
arr.push(60);
alert("After Push (add 60): " + arr);
// pop
var popped = arr.pop();
alert("After Pop (remove last): " + arr + "\nPopped Element: " + popped);
}
</script></body></html>
<script>
function demonstrateStringFunctions() {
var str = document.getElementById('inputString').value;
if (str) {
alert("Original String: " + str +
"\nUppercase: " + str.toUpperCase() +
"\nLowercase: " + str.toLowerCase());
} else {
alert("Please enter a string!");
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Evaluate Expression</title></head><body>
<input type="text" id="expression" placeholder="Enter arithmetic expression">
<button onclick="evaluateExpression()">Evaluate</button>
<script>
function evaluateExpression() {
try {
var expression = document.getElementById('expression').value;
if (!expression) {
alert("Please enter an expression!");
return;
}
var result = eval(expression);
alert("Result of '" + expression + "': " + result);
} catch (error) {
alert("Invalid expression!");
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Change Background Color</title></head><body>
<button onclick="askToChangeColor()">Change Background Color</button>
<script>
function askToChangeColor() {
var userResponse = confirm("Do you want to change the background color?");
if (userResponse) {
var color = prompt("Enter the color you want:");
if (color) {
document.body.style.backgroundColor = color;
} else {
alert("No color entered. Background color not changed.");
}
} else {
alert("You decided not to change the color.");
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Array Operations</title></head><body>
<button onclick="performArrayOperations()">Perform Array Operations</button>
<script>
function performArrayOperations() {
var arr = [1, 2, 3, 4, 5];
alert("Original Array: " + arr);
// Splice: Remove two elements starting at index 1 and add new elements
arr.splice(1, 2, 9, 10);
alert("After splice(1, 2, 9, 10): " + arr);
<script>
function calculatePercentage() {
var marksObtained = parseFloat(document.getElementById('marksObtained').value);
var totalMarks = parseFloat(document.getElementById('totalMarks').value);
<script>
function checkPalindrome() {
var str = document.getElementById('inputString').value;
var reversedStr = str.split('').reverse().join('');
if (str === reversedStr) {
alert("The string is a palindrome.");
} else {
alert("The string is not a palindrome.");
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>College Registration Form</title></head><body>
<h2>College Registration Form</h2>
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="course">Course:</label>
<select id="course" name="course">
<option value="engineering">Engineering</option>
<option value="science">Science</option>
<option value="arts">Arts</option>
</select><br><br>
<button type="submit">Submit</button>
</form></body></html>
<!DOCTYPE html><html><head>
<title>Handle onblur Event</title></head><body>
<h2>Form with onblur Event</h2>
<form>
<label for="name">Name:</label>
<input type="text" id="name" onblur="validateName()" placeholder="Enter your name">
<span id="error"></span><br><br>
<button type="submit">Submit</button>
</form>
<script>
function validateName() {
var nameInput = document.getElementById('name').value;
var errorSpan = document.getElementById('error');
if (nameInput === "") {
errorSpan.innerText = "Name cannot be empty!";
errorSpan.style.color = "red";
} else {
errorSpan.innerText = "";
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Handle onload Event</title></head><body onload="welcomeMessage()">
<h2>Form with onload Event</h2>
<form>
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Enter your email"><br><br>
<button type="submit">Submit</button>
</form>
<script>
function welcomeMessage() {
alert("Welcome! Please fill out the form.");
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Handle onclick Event</title></head><body>
<h2>Form with onclick Event</h2>
<form>
<label for="username">Username:</label>
<input type="text" id="username"><br><br>
<script>
function handleClick() {
var username = document.getElementById('username').value;
if (username === "") {
alert("Please enter your username.");
} else {
alert("Hello, " + username + "! Form submitted successfully.");
}
}
</script></body></html>
<script>
function useIntrinsicFunctions() {
// Math intrinsic function
var randomNum = Math.random();
alert("Random Number: " + randomNum);
</script></body></html>
<!DOCTYPE html><html><head>
<title>Session Cookie</title></head><body>
<button onclick="createSessionCookie()">Create Session Cookie</button>
<button onclick="showCookie()">Show Cookie</button>
<script>
function createSessionCookie() {
document.cookie = "username=Mayur; path=/";
alert("Session cookie created.");
}
function showCookie() {
alert("Cookies: " + document.cookie);
}
</script></body></html>
<script>
function createPersistentCookie() {
var expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + 7); // Expires in 7 days
document.cookie = "location=Nashik; expires=" + expiryDate.toUTCString() + "; path=/";
alert("Persistent cookie created.");
}
function showCookie() {
alert("Cookies: " + document.cookie);
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Check Capitalized First Letter</title></head><body>
<input type="text" id="inputString" placeholder="Enter a string">
<button onclick="checkCapitalized()">Check</button>
<script>
function checkCapitalized() {
var str = document.getElementById('inputString').value;
if (str && str[0] === str[0].toUpperCase()) {
alert("The first letter is capitalized.");
} else {
alert("The first letter is not capitalized.");
}
}
</script></body></html>
<!DOCTYPE html><html><head>
<title>Image and Text Rollover</title></head><body>
<h2 id="text">Hover over the image</h2>
<img id="image" src="image1.jpg" alt="Image 1"
onmouseover="rolloverImage()"
onmouseout="resetImage()"
style="width:200px; height:200px;">
<script>
function rolloverImage() {
document.getElementById("image").src = "image2.jpg";
document.getElementById("text").innerText = "Mouse is over the image";
}
function resetImage() {
document.getElementById("image").src = "image1.jpg";
document.getElementById("text").innerText = "Hover over the image";
}
</script></body></html>
<!DOCTYPE html>
<html>
<head>
<title>Frameset Example</title>
</head>
<frameset rows="50%,50%">
<frameset cols="33%,33%,34%">
<frame src="frame1.html" name="frame1">
<frame src="frame3.html" name="frame3">
<frame src="frame4.html" name="frame4">
</frameset>
<frame src="frame2.html" name="frame2">
</frameset>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Frameset Example</title>
</head>
<frameset rows="50%,50%">
<frameset cols="33%,33%,34%">
<frame src="frame1.html" name="frame1">
<frame src="frame3.html" name="frame3">
<frame src="frame4.html" name="frame4">
</frameset>
<frame src="frame2.html" name="frame2">
</frameset>
</html>