CSS Imp Programs
CSS Imp Programs
var result;
switch (operator) {
case "+":
result = operand1 + operand2;
break;
case "-":
result = operand1 - operand2;
break;
case "*":
result = operand1 * operand2;
break;
case "/":
if (operand2 !== 0) {
result = operand1 / operand2;
} else {
result = "Cannot divide by zero!";
}
break;
default:
result = "Invalid operator";
}
2. Write a java script program that will remove the duplicate element from
an array.
<!DOCTYPE html>
<html lang="en">
<head> </head>
<body>
<script>
function removeDuplicatesFromArray(inputArray) {
// Use Set to automatically remove duplicates
const uniqueArray = [...new Set(inputArray)];
return uniqueArray;
}
// Example usage:
const inputArray = [1, 2, 3, 4, 2, 5, 6, 1, 7, 8, 8];
const resultArray = removeDuplicatesFromArray(inputArray);
3. Write a java script program that will display list of students in ascending
order according to the marks and calculate the average performance of
the class.
Student name Marks
Amit 34
Sumit 45
Rakesh 27
<html>
<head>
<script>
var students = [
{ name: "Amit", marks: 70 },
{ name: "Sumit", marks: 78 },
{ name: "Abhishek", marks: 71 },
];
function sortStudentsBymarks(students) {
return students.sort(function (a, b) {
return a.marks - b.marks;
});
}
function displaySortStudents(sortedStudents) {
document.write("Sorted list");
for (i = 0; i < sortedStudents.length; i++) {
document.write(
sortedStudents[i].name + " : " + sortedStudents[i].marks
);
document.write("<br>");
}
}
var sortedStudents = sortStudentsBymarks(students);
displaySortStudents(sortedStudents);
</script>
<title>Css</title>
</head>
<body></body>
</html>
4. Write a java script function to merge two arrays and remove all duplicate
values.
<!DOCTYPE html>
<html lang="en">
<head> </head>
<body>
<script>
function mergeAndRemoveDuplicates(array1, array2) {
// Merge the arrays
const mergedArray = array1.concat(array2);
return uniqueArray;
}
// Example usage:
const array1 = [1, 2, 3, 4, 5];
const array2 = [3, 4, 5, 6, 7];
5. Write a simple java script code to print all prime numbers between 0 to n
Take input from user.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Prime Number Finder</title>
</head>
<body>
<h2>Prime Number Finder</h2>
<p id="result"></p>
<script>
function isPrime(num) {
if (num <= 1) return false;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) return false;
}
return true;
}
function findPrimes() {
const inputNumber = document.getElementById("inputNumber").value;
const resultElement = document.getElementById("result");
resultElement.innerHTML = "";
function readCookie() {
var cookies = document.cookie.split(";");
var userName;
if (userName) {
alert("User's Name: " + userName);
} else {
alert("Cookie not found or expired!");
}
}
function deleteCookie() {
// Set the 'userName' cookie to expire in the past
document.cookie =
"userName=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/";
<script>
function validateEmail() {
// Get the email input value
var email = document.getElementById("email").value;
<script>
function validatePhoneNumber() {
// Get the input value
var phoneNumber = document.getElementById("phoneNumber").value;
9. Text rollover
<html>
<head>
<script></script>
<title>Frame Program</title>
</head>
<body>
<table>
<tr>
<td>
<img src="img1.jpg" height="400px" width="400px" name="myimg" />
</td>
<td>
<a onmouseover="document.myimg.src='img1.jpg'">Image 1</a><br />
<a onmouseover="document.myimg.src='img2.jpg'">Image 2</a><br />
<a onmouseover="document.myimg.src='img1.jpg'">Image 3</a><br />
</td>
</tr>
</table>
</body>
</html>
10. Right click disable
<html>
<head>
<script>
function RightClickDisable() {
alert("Not allowed");
return false;
}
function InternetExp() {
if (event.button == 2) {
// main logic
RightClickDisable();
return false;
}
}
document.oncontextmenu = new Function("RightClickDisable();return false");
</script>
<title>Frame Program</title>
</head>
<body></body>
</html>
function displayLinks() {
document.location.href = "http://" + MyBannerLinks[banner_count];
}
function displayBanner() {
if (document.images) {
banner_count++;
if (banner_count == MyBanners.length) {
banner_count = 0;
}
document.bannerchange.src = MyBanners[banner_count];
setTimeout("displayBanner()", 2000);
}
}
</script>
<title>Frame Program</title>
</head>
<body onload="displayBanner()">
<a href="javascript: displayLinks()">
<img src="img1.jpg" name="bannerchange" />
</a>
</body>
</html>
13. Palindrome
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Palindrome Checker</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
</style>
</head>
<body>
<h2>Palindrome Checker</h2>
<label for="inputString">Enter a string: </label>
<input type="text" id="inputString" />
<button onclick="checkPalindrome()">Check</button>
<p id="result"></p>
<script>
function checkPalindrome() {
// Get the input string from the user
var inputString = document.getElementById("inputString").value;