cssl Assignment
cssl Assignment
<html>
<head>
<title>display pathname</title>
</head>
<body>
<script type="text/javascript">
function display(){
var currentpath = window.location.pathname;
document.write("pathname = "+currentpath);
};
</script>
<form name="myform">
<input type="button" value="get pathname" onclick="display()">
</form>
</body>
</html>
2. Write a JavaScript that initializes an array called “Fruits” with names of five
fruits. The script then displays the array in a message box.
<html>
<head>
<title>Array</title>
</head>
<body>
<script type="text/javascript">
var Fruits = new Array(5);
Fruits[0]="apple";
Fruits[1]="banana";
Fruits[2]="mango";
Fruits[3]="pair";
Fruits[4]="papaya";
alert("array element="+Fruits);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>program to check if the string is palindrome or not</title>
</head>
<body>
<script type="text/javascript">
function checkPalindrome(string)
{
const len = string.length;
for (var i = 0; i < len / 2; i++)
{
if (string[i] !== string[len - 1 - i])
{
return 'It is not a palindrome';
}
}
return 'It is a palindrome';
}
const string = prompt('Enter a string: ');
// call the function
const value = checkPalindrome(string);
document.write(value);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
5. Write a javascript function to generate Fibonacci series till user defined limit.
<html>
<head>
<title>Fibonacci series </title>
</head>
<body>
<script type=”text/javascript”>
var n1=0,n2=1,i;
var num= parseInt(prompt(“enter limit for generate fibonacci series ”));
for(i=0;i<=num;i++)
{
}