0% found this document useful (0 votes)
38 views5 pages

191202C0058 Exp5

1. The document discusses a lab experiment on implementing strings in JavaScript. It describes two ways to create strings - using string literals or the String object. 2. The document provides examples of string operations like removing whitespace using trim(), converting to title case using replace() and loops. 3. It includes two exercises - one to check if a string is a palindrome, and another to count the vowels in a given string. Code snippets are given for both problems.

Uploaded by

Hrushikesh Bhoir
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)
38 views5 pages

191202C0058 Exp5

1. The document discusses a lab experiment on implementing strings in JavaScript. It describes two ways to create strings - using string literals or the String object. 2. The document provides examples of string operations like removing whitespace using trim(), converting to title case using replace() and loops. 3. It includes two exercises - one to check if a string is a palindrome, and another to count the vowels in a given string. Code snippets are given for both problems.

Uploaded by

Hrushikesh Bhoir
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
You are on page 1/ 5

DEPARTMENT OF INFORMATION TECHNOLOGY

Subject: Operating Systems Subject Code: 22519


Semester: 5th Course: IF5IC
Laboratory No: L003C Name of Subject Teacher: Yogita Jore
Name of Student: Indu Medisetti Roll Id: 19202C0058

Experiment No: 5
Aim Develop Java Script to implement Strings.

Theory: -
The JavaScript string is an object that represents a sequence of characters.
There are 2 ways to create string in JavaScript
1. By string literal
2. By string object (using new keyword)
1) By string literal
The string literal is created using double quotes. The syntax of creating string
using string literal is given below:
var stringname="string value";

2) By string object (using new keyword)


The syntax of creating string object using new keyword is given below:
var stringname=new String("string literal");

Practical related questions:


1. How to remove the white spaces between the strings?
We use Trim () function to remove the white spaces between the strings.

2. How to convert text in lowercase into title case?


We can convert text in lower into title case by
a. By using replace () function
b. By using for loop to title case a string

Exercise:
1. Write a program to check whether the given staring is palindrome or not?

192020058
Code

<html>
<head> <title> Palindrome </title>
</head>
<body>
<script>
function validatePalin(str) {
// get the total length of the words
const len = string.length;
// Use for loop to divide the words into 2 half
for (let i = 0; i < len / 2; i++) {
// validate the first and last characters are same
if (string[i] !== string[len - 1 - i]) {
alert( 'It is not a palindrome');
}
}
alert( 'It is a palindrome');
}
// accept the string or number from the prompt
const string = prompt('Enter a string or number: ');
const value = validatePalin(string);
console.log(value);
</script>
</body>
</html>

Output: -

192020058
2. Write a program to count the number of vowels into the string?

Code: -
<html>
<head>

192020058
<title>Count Vowels</title>
</head>
<body>
<script>
function getVowels(string) {
var Vowels = 'aAeEiIoOuU';
var vowelsCount = 0;
for(var i = 0; i < string.length ; i++) {
if (Vowels.indexOf(string[i]) !== -1) {
vowelsCount += 1;
}
}
return vowelsCount;
}
document.write("The Number of vowels in -"+
" MY name is INDU: "
+ getVowels("I am INDU"));
</script>
</body>
</html>

Output: -

Conclusion:
We have learnt about how to print message and how to perform vowels operation
using alert and prompt.

Marks Obtained Dated Signature of Teacher


Process Related Product Total
(15) Related (50)
(35)

192020058
192020058

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy