Javascript Record Progrms
Javascript Record Progrms
Write a JavaScript program to find the area and circumference of a circle (use
form)
<!doctype html>
<html>
<head>
<script>
function area_crf()
{
var radius, area, circumference;
radius= parseInt(document.getElementById("rad").value);
area=3.14*radius*radius;
circumference=2*3.14*radius;
document.getElementById("answer").value = area;
document.getElementById("answer1").value = circumference;
}
</script>
</head>
<body>
<p>Enter the Radius: <input id="rad"></p>
<button onclick="area_crf()">AREA-CIRCUMFERENCE-CIRCLE</button>
<p>Area = <input id="answer"></p>
<p>Circumference= <input id="answer1"></p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Dialog Box Example</title>
</head>
<body>
<script>
// First dialog box: Ask for the user's favorite color
let favoriteColor = prompt("What is your favorite color?");
// Second dialog box: Ask for confirmation to proceed with the color choice
let isConfirmed = confirm("You entered: " + favoriteColor + ". Do you want to
continue?");
</body>
</html>
3. Write a JavaScript program to create a color palette and change the background
color (using
mouseover event).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Palette</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
.palette {
display: inline-block;
margin: 0 auto;
}
.color-box {
width: 100px;
height: 100px;
display: inline-block;
margin: 10px;
cursor: pointer;
border: 2px solid #333;
}
</style>
</head>
<body>
<script>
// Get all the color boxes
const colorBoxes = document.querySelectorAll('.color-box');
</body>
</html>
4. Write a JavaScript program to change the background color of the document using
an arrayof colors.
(Array)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change Background Color</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<script>
// Array of colors
const colors = ["red", "blue", "green", "yellow", "purple", "orange", "pink",
"teal"];
// Increment the color index, and reset it to 0 if it exceeds the array length
colorIndex = (colorIndex + 1) % colors.length;
}
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Browser Detection</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
.compatible {
color: green;
}
.incompatible {
color: red;
}
</style>
</head>
<body>
<script>
// Function to detect the browser
function detectBrowser() {
const userAgent = navigator.userAgent;
if (userAgent.includes("Chrome")) {
return "Chrome";
} else if (userAgent.includes("Firefox")) {
return "Firefox";
} else if (userAgent.includes("Safari") && !userAgent.includes("Chrome")) {
return "Safari";
} else if (userAgent.includes("Edg")) {
return "Edge";
} else if (userAgent.includes("MSIE") || userAgent.includes("Trident")) {
return "Internet Explorer";
} else {
return "Unknown";
}
}
// Function to check browser compatibility
function isCompatible(browser) {
const compatibleBrowsers = ["Chrome", "Firefox", "Edge", "Safari"];
return compatibleBrowsers.includes(browser);
}
if (isCompatible(browser)) {
document.getElementById('compatibility-message').textContent = "Your browser is
compatible!";
document.getElementById('compatibility-message').classList.add("compatible");
} else {
document.getElementById('compatibility-message').textContent = "Your browser is
not compatible. Please update or use a different browser.";
document.getElementById('compatibility-message').classList.add("incompatible");
}
</script>
</body>
</html>