All JS Output-1
All JS Output-1
01
Roll No. 45
Program:-
<html>
<head>
<title> To generate the multiplication table of a given number. </title>
</head>
<body>
<script>
var table = 10;
for(var i=1;i<=10;i++)
{document.write(table + "x"+ i + "="+ i*table +"<br>"); // 10* 1= 10
}
</script>
</body>
</html>
Practical No. 02
Roll No. 45
Output:
Program:- To calculate area of Rectangle
<html>
<head>
<title> JavaScript Program To Calculate The Area of a Rectangle </title>
</head>
<body>
<script type="text/javascript">
/*
Javascript program to find the area of a rectangle
*/
var l, w, a;
l = 8;
w = 6;
/* Calculate area of rectangle */
a = l * w;
document.write("Area of rectangle = " + a + " units");
</script>
</body>
</html>
Output:
Program:- To calculate the area of circle
<html>
<head>
<title> JavaScript Program To Calculate The Area of a Circle </title>
</head>
<body>
<h1>Area of a circle</h1>
Enter the radius for your circle:
<input type="text" id="txtRadius" />
<input type="button" value="Calculate" onClick=CalculateArea() />
<script>
function CalculateArea() {
var radius = document.getElementById('txtRadius').value;
alert("The area of the circle is " + (radius * radius * Math.PI));
}
</script>
</body>
</html>
Output:
Practical No. 03
Roll No. 45
Program :-
<html>
<head>
<title> program to reverse a string </title>
</head>
<body>
<script type="text/javascript">
function reverseString(str) {
// return a new array of strings
const arrayStrings = str.split("");
// reverse the new created array elements
const reverseArray = arrayStrings.reverse();
// join all elements of the array into a string
const joinArray = reverseArray.join("");
// return the reversed string
return joinArray;
}
// take input from the user
const string = prompt('Enter a string: ');
const result = reverseString(string);
console.log(result);
</script>
</body>
</html>
Output:
Program: Replace characters of a string
<html>
<head>
<title> program to reverse a string </title>
</head>
<body>
<script type="text/javascript">
// program to replace a character of a string
const string = 'Hello!!! I am Mohit Wani';
// regex expression
const regex = /red/g;
// replace the characters
const newText = string.replace(regex, 'blue');
// display the result
console.log(newText);
</script>
</body>
</html>
Output:
Program: String is Palindrome
</head>
<body>
<script type="text/javascript">
// program to check if the string is palindrome or not
function checkPalindrome(string) {
// convert string to an array
const arrayValues = string.split('');
// reverse the array values
const reverseArrayValues = arrayValues.reverse();
// convert array to string
const reverseString = reverseArrayValues.join('');
if(string == reverseString) {
console.log('It is a palindrome');
}
else {
console.log('It is not a palindrome');
}
}
//take input
const string = prompt('Enter a string: ');
checkPalindrome(string);
</script>
</body>
</html>
Output:
Practical No. 04
Roll No. 45
Output:
Program: Using toUpperCase()
<html>
<head>
<title> program to perform string comparison </title>
</head>
<body>
<script type="text/javascript">
const string1 = 'Are you like JavaScript Program';
const string2 = 'javascript program';
// compare both strings
const result = string1.toUpperCase() === string2.toUpperCase();
if(result) {
console.log('The strings are similar.');
} else {
console.log('The strings are not similar.');
}
</script>
</body>
</html>
Output:
Program:JS String Comparison Using RegEx
<html>
<head>
<title> program to perform string comparison </title>
</head>
<body>
<script type="text/javascript">
const string1 = 'JavaScript Program';
const string2 = 'javascript program';
// create regex
const pattern = new RegExp(string1, "gi");
// compare the stings
const result = pattern.test(string2)
if(result) {
console.log('The strings are similar.');
} else {
console.log('The strings are not similar.');
}
</script>
</body>
</html>
Output:
Program: localeCompare() Method
<html>
<head>
<title> program to perform case insensitive string comparison </title>
</head>
<body>
<script type="text/javascript">
const string1 = 'This is the JavaScript Program';
const string2 = 'this is the javascript program';
const result = string1.localeCompare(string2, undefined, { sensitivity: 'base' });
if(result == 0) {
console.log('The strings are similar.');
} else {
console.log('The strings are not similar.');
}
</script>
</body>
</html>
Output: