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

Javascript Program

The document contains three JavaScript programs with specific aims. The first program sorts an array of numbers in ascending order, the second changes the background color of a paragraph based on user interaction, and the third counts the number of vowels in a given string. Each program is presented in HTML format with accompanying scripts.

Uploaded by

priyaganesh12345
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)
1 views4 pages

Javascript Program

The document contains three JavaScript programs with specific aims. The first program sorts an array of numbers in ascending order, the second changes the background color of a paragraph based on user interaction, and the third counts the number of vowels in a given string. Each program is presented in HTML format with accompanying scripts.

Uploaded by

priyaganesh12345
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

Javascript program:

Aim :

Write the java script program to user defined function to get array of values
and sort them in ascending order.

Program:

<html>

<body>

<h2>The sort Method</h2>

<p>Sort the array in ascending order:</p>

<p id="line1"></p>

<p id="line2"></p>

<script>

const points = [40, 100, 1, 5, 25, 10];

[Link]("line1").innerHTML = points;

[Link](function(a, b){return a - b});

[Link]("line2").innerHTML = points;

</script>

</body>

</html>
Aim :

Write the java script program to set the background color of a paragraph
with user choice.

Program:

<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<p id="myPara">Change the Background Color of Paragraph in JavaScript</p>
<button type="button" onclick="changeBackground()">Click Me</button>
<script>
function changeBackground()
{
var element = [Link]("myPara");
[Link] = "green";
}
</script>
</body>
</html>
Aim :

Write the java script program to count the no of vowels in a given string

Program:

<html>
<body>
<script>
function noOfVowels(string)
{
var listOfVowels = 'aAeEiIoOuU';
var vowelsCount = 0;
for(var i = 0; i < [Link] ; i++)
{
if ([Link](string[i]) !== -1)
{
vowelsCount += 1;
}
}
return vowelsCount;
}
[Link](noOfVowels("Actions speak louder than words"));
</script>
</body>
</html>

You might also like