0% found this document useful (0 votes)
29 views

5th Css

The document describes a student's practical assignment on using strings in JavaScript. It includes 4 code examples that 1) create strings using literals and the String object, 2) alternate the case of each character in a string, 3) demonstrate various string methods like length, toUpperCase, and substring, and 4) concatenate, replace, and slice strings. The output of running the code is also displayed.

Uploaded by

Ganesh Ekambe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

5th Css

The document describes a student's practical assignment on using strings in JavaScript. It includes 4 code examples that 1) create strings using literals and the String object, 2) alternate the case of each character in a string, 3) demonstrate various string methods like length, toUpperCase, and substring, and 4) concatenate, replace, and slice strings. The output of running the code is also displayed.

Uploaded by

Ganesh Ekambe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 05

Practical No-5. Develop javascript to implement Strings.

Code:
1. By string Literal & by string object

<html>
<head>
<title> String Example</title>
</head>
<script type="text/Javascript">
var str ="my Name is Ganesh Ekambe";
document.write(str);
var str1=new String('<br>'+"I am studied in Co5I
class" );
document.write(str1);
</script>
</html>

Output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 05

2. code
<!DOCTYPE html>
<html>
<script>
function alternateCase(inputString) {
let result = '';
for (let i = 0; i < inputString.length; i++) {
if (i % 2 === 0) {
result += inputString[i].toUpperCase();
} else {
result += inputString[i].toLowerCase();
}
}
return result;
}

const originalString = "ganesh";


const modifiedString = alternateCase(originalString);
document.write(modifiedString);
</script>
</body>
</html>

Output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 05

3. String Methods

<!DOCTYPE html>
<html>
<head>
<title>String Methods Example</title>
</head>
<body>

<h1>String Methods Example</h1>

<script>
var originalString = "Client side ";
document.write(originalString);

var length = originalString.length;


document.write("<p>1. Length of the string: " + length + "</p>");

var uppercaseString = originalString.toUpperCase();


document.write("<p>2. Uppercase string: " + uppercaseString + "</p>");

var lowercaseString = originalString.toLowerCase();


document.write("<p>3. Lowercase string: " + lowercaseString + "</p>");

var substring = originalString.substring(0, 6);


document.write("<p>4. Substring: " + substring + "</p>");

var indexOfside = originalString.indexOf("Side");


document.write("<p>5. Index of 'side': " + indexOfside + "</p>");

var replacedString = originalString.replace("client", "javascript");


document.write("<p>6. Replaced string: " + replacedString + "</p>");

var splitArray = originalString.split(",");


document.write("<p>7. Split string: " + splitArray + "</p>");
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 05

var startsWithClient = originalString.startsWith("");


document.write("<p>8. Starts with 'Client': " + startsWithClient + "</p>");

var endsWithprogram = originalString.endsWith("program");


document.write("<p>9. Ends with 'program': " + endsWithprogram + "</p>");
</script>

</body>
</html>

Output
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 05

4. String Methods

<!DOCTYPE html>
<html>
<head>
<title>String Methods Example</title>
</head>
<body>
<script>
var str1 = "Gramin";
var str2 = "Collage";

var concatenatedString = str1.concat(" ", str2);


var lengthOfString = concatenatedString.length;
var replacedString = concatenatedString.replace("Collage",
"Campus");
var SliceString = concatenatedString.slice(4, 10);

document.write("<p>1. Original Strings: " + str1 + " " + str2 +


"</p>");
document.write("<p> 2.Concatenated String: " +
concatenatedString + "</p>");
document.write("<p> 3.Length of String: " + lengthOfString +
"</p>");
document.write("<p>4. Replaced String: " + replacedString +
"</p>");
document.write("<p>5. Slice String: " + SliceString + "</p>");
</script>
</body>
</html>
Client side Scripting Language (22519)

Name of Student: Ekambe Ganesh Roll No.: 53


Practical No. 05

Output:

You might also like