LAB PRograms 1-3
LAB PRograms 1-3
Program 1: HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Console and ALERT</title>
</head>
<body>
<script src="pgm1.js"></script>
</body>
</html>
console.log("Hello World");
Program 1b: Create an array of 5 cities and perform the following operations: Log the
total number of cities. Add a new city at the end. Remove the first city. Find and log the
index of a specific city.
// Declaration of Array
cities=["New Dehli","Mumbai", "Bengaluru","Kolkata", "Chennai"];
2. Read a string from the user, Find its length. Extract the word "JavaScript" using
substring () or slice (). Replace one word with another word and log the new string.
Write a function isPalindrome(str) that checks if a given string is a palindrome (reads
the same backward).
ind=str1.indexOf("JavaScript")
console.log("Index at which JavaScript found "+ind)
function isPalindrome(str) {
const reversed = str.split('').reverse().join('');
return str === reversed;
}
if (res1==true)
{
console.log(str2+ " is palindrome");
}
else
{
console.log(str2+ " is not palindrome")
}
3. Create an object student with properties: name (string), grade (number), subjects
(array), displayInfo() (method to log the student's details) Write a script to
dynamically add a passed property to the student object, with a value of true or
false based on their grade. Create a loop to log all keys and values of the student
object.
student={nam:"Rama",grade:58,subjects:["Science","Mathematics", "English"] };
function displayinfo()
{
console.log(student);
}
displayinfo();
/*passed property to the student object, with a value of true or false based on their grade. */
if (student.grade>40)
console.log("Pass");
else
console.log("Fail")
console.log(value);
}