1.
Write a JavaScript that accepts a string and searches for the pattern “MSBTE” in the
given string. If the pattern is found, JavaScript will display that “Pattern is found” else
display “Pattern is not found: -
<script>
let a=prompt("Enter a String");
if(a.match("MSBTE"))
document.write("Pattern is found");
else
document.write("Pattern is not found");
</script>
2. Write a Java script that will replace following specified value with another value in a
string. String = “ I will fail” Replace “fail” by “pass”
<script>
let a="I will fail";
document.write(a.replace("fail","pass"));
</script>
3. Write JavaScript code to perform following operations on string. (Use split() method)
Input String : “Sudha Narayana Murthy” Display output as
First Name: Sudha
Middle Name: Narayana
Last Name: Murthy
<html>
<body>
<script>
let a="Sudha Narayana Murthy";
let b=a.split(" ");
document.write("First name:"+b[0]+"<br>");
document.write("Middle name:"+b[1]+"<br>");
document.write("Last name:"+b[2]);
</script>
</body>
</html>
4. Write a javascript function that accepts a string as a parameter and find the length of
the string.
<script>
function no(a)
document.write(a.length);
no("Sudha Narayana Murthy");
</script>
5. Write a javascript to checks whether a passed string is palindrome or not.
<script>
function checkPalindrome(string) {
const len = string.length;
for (let 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: ');
const value = checkPalindrome(string);
document.write(value);
</script>
6. Write a javascript function to generate Fibonacci series till user defined limit.
<script>
var n1 = 0, n2 = 1, next_num, i;
var num = parseInt (prompt (" Enter the limit for Fibonacci Series "));
document.write( "Fibonacci Series: ");
for ( i = 1; i <= num; i++)
{ document.write (" <br> " + n1);
next_num = n1 + n2;
n1 = n2;
n2 = next_num;
</script>
7. Write a JavaScript function to count the number of vowels in a given string.
let a=prompt("Enter your name");
let b="aeiouAEIOU";
let count=0,char,char1;
for(let i=0;i<a.length;i++)
char=a[i];
for(let j=0 ;j<b.length;j++)
char1=b[j];
if(char==char1)
count=count+1;
document.write("Number of vowels in "+a+" are "+count);
</script>
8. Write a JavaScript that find and displays number of duplicate values in an array.
let a=["a","b","c","d","e"];
let b=["z","c","y","x","a"];
let c=[];
let count=0,char,char1;
for(let i=0;i<a.length;i++)
char=a[i];
for(let j=0;j<b.length;j++)
char1=b[j];
if(char==char1)
count++;
c.push(char1);
document.write("Duplicate Values: "+c+"<br>");
document.write("Count of Duplicate Values: "+count);
9. Develop JavaScript to convert the given character to Unicode and vice versa.
<script>
let unicodeValue = 65;
let character = String.fromCharCode(unicodeValue);
document.write(character);
let character1="A";
let unicodeValue1 = character1.codePointAt();
document.write("<br>"+unicodeValue1);
</script>
10. Write a JavaScript function to insert a string within a string at a particular position.
<script>
let str = "HowDoing";
let subStr = "areyou";
let pos = 3;
document.write(str.substr(0, pos) + subStr + str.substr(pos))
</script>