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>