0% found this document useful (0 votes)
2 views3 pages

String Manipulation JavaScript Examples

The document contains three HTML programs that demonstrate string manipulation techniques. The first program reverses a string, the second replaces specified characters in a string, and the third checks if a string is a palindrome. Each program includes JavaScript code and prompts for user input, displaying the results on a webpage.

Uploaded by

Shreya Patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

String Manipulation JavaScript Examples

The document contains three HTML programs that demonstrate string manipulation techniques. The first program reverses a string, the second replaces specified characters in a string, and the third checks if a string is a palindrome. Each program includes JavaScript code and prompts for user input, displaying the results on a webpage.

Uploaded by

Shreya Patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT – 03

1. REVERSE A STRING

PROGRAM: -

<!DOCTYPE html>
<html>
<head>
<title>Reverse String</title>
</head>
<body>
<script>
let str = prompt("Enter a string to reverse:");
let reversed = "";

for (let i = [Link] - 1; i >= 0; i--) {


reversed += str[i];
}

[Link]("Original String: " + str + "<br>");


[Link]("Reversed String: " + reversed);
</script>
</body>
</html>

OUTPUT: -

2. REPLACE CHARACTERS OF A STRING.


PROGRAM: -

<!DOCTYPE html>
<html>
<head>
<title>Replace Characters</title>
</head>
<body>
<script>
let str = prompt("Enter a string:");
let oldChar = prompt("Enter the character to replace:");
let newChar = prompt("Enter the new character:");

let result = "";

for (let i = 0; i < [Link]; i++) {


if (str[i] === oldChar) {
result += newChar;
} else {
result += str[i];
}
}

[Link]("Original String: " + str + "<br>");


[Link]("Modified String: " + result);
</script>
</body>
</html>

OUTPUT: -

3. STRING IS PALINDROME

PROGRAM: -

<!DOCTYPE html>
<html>
<head>
<title>Palindrome Check</title>
</head>
<body>
<script>
let str = prompt("Enter a string:");
let reversed = "";

for (let i = [Link] - 1; i >= 0; i--) {


reversed += str[i];
}

if (str === reversed) {


[Link]("Yes, it is a palindrome.");
} else {
[Link]("No, it is not a palindrome.");
}
</script>
</body>
</html>

OUTPUT: -

You might also like