0% found this document useful (0 votes)
6 views4 pages

Css

The document contains five separate JavaScript programs embedded in HTML. Each program performs a specific task: checking if a number is a multiple of 3 or 7, displaying 'Hello World!', manipulating a string to replace 'like' with 'know' and splitting it, counting vowels in a string, and finding duplicate values in an integer array. These examples demonstrate basic JavaScript functionalities and string manipulations.

Uploaded by

tanvi.digikraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Css

The document contains five separate JavaScript programs embedded in HTML. Each program performs a specific task: checking if a number is a multiple of 3 or 7, displaying 'Hello World!', manipulating a string to replace 'like' with 'know' and splitting it, counting vowels in a string, and finding duplicate values in an integer array. These examples demonstrate basic JavaScript functionalities and string manipulations.

Uploaded by

tanvi.digikraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. WAP to check if a given positive number is a multiple of 3 or 7.

<!DOCTYPE html>
<html>
<head>
<title>Multiple of 3 or 7</title>
</head>
<body>
<script>
function checkMultiple(num) {
if (num % 3 === 0 && num % 7 === 0) {
return num + " is a multiple of both 3 and 7.";
} else if (num % 3 === 0) {
return num + " is a multiple of 3.";
} else if (num % 7 === 0) {
return num + " is a multiple of 7.";
} else {
return num + " is not a multiple of 3 or 7.";
}
}

// Prompt the user for input


let number = prompt("Enter a number:");
number = parseInt(number); // Convert the input to an integer
document.write(checkMultiple(number)); // Display the result on the page
</script>
</body>
</html>

2. WAP to display “Hello World!” in JS.


<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World Example</title>
</head>
<body>
<script>
document.write("<i>Hello World!</i>");
</script>
</body>
</html>
3. WAP to replace “like” by “know” and divide the string on the basis
of white spaces from the 7th index and display results. (Given string
= “I like JavaScript programming”)

<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
<script>
// Given string
let givenString = "I like JavaScript programming";

// Replace "like" with "know"


let modifiedString = givenString.replace("like", "know");

// Split the string at the 7th index


let part1 = modifiedString.slice(0, 7);
let part2 = modifiedString.slice(7);

// Display results
document.write('<p>Modified String: ' + modifiedString + '</p>');
document.write('<p>Part 1: ' + part1 + '</p>');
document.write('<p>Part 2: ' + part2 + '</p>');
</script>
</body>
</html>

4. WAP to count and display the number of vowels in a given string.

<!DOCTYPE html>

<html>

<head>

<title>Count Vowels</title>

</head>

<body>

<script>

function countVowels(str) {
// Define vowels

const vowels = 'aeiouAEIOU';

let count = 0;

// Count vowels

for (let char of str) {

if (vowels.includes(char)) {

count++;

return count;

// Given string

let givenString = "This is a simple example.";

// Count vowels

let vowelCount = countVowels(givenString);

// Display result

document.write('Number of Vowels: ' + vowelCount);

</script>

</body>

</html>

5. WAP to find and display the duplicate values along with the count in an integer array.

<!DOCTYPE html>
<html>
<head>
<title>Find Duplicates</title>
</head>
<body>
<script>
function findDuplicates(arr) {
const counts = {};
const duplicates = {};

// Count occurrences of each number


for (const num of arr) {
counts[num] = (counts[num] || 0) + 1;
}

// Find duplicates
for (const num in counts) {
if (counts[num] > 1) {
duplicates[num] = counts[num];
}
}

return duplicates;
}

// Given array
const givenArray = [1, 2, 3, 2, 4, 5, 1, 6, 1];

// Find duplicates
const duplicateCounts = findDuplicates(givenArray);

// Display result
document.write('<p>Given Array: ' + givenArray + '</p>');
document.write('<p>Duplicates and Counts:</p>');
for (const [num, count] of Object.entries(duplicateCounts)) {
document.write('<p>Number ' + num + ' appears ' + count + ' times</p>');
}
</script>
</body>
</html>

You might also like