Chapter 21-25: STRING METHODS
Write a program that takes two user inputs for first and last name using prompt and merge them in a new variable titled fullName. Greet the user using his full name.
Write a program to take a user input about his favorite mobile phone model. Find and display the length of user input in your browser
Write a program to find the index of letter “n” in the word “Pakistani” and display the result in your browser .
Write a program to find the last index of letter “l” in the word “Hello World” and display the result in your browser.
Write a program to find the character at 3rd index in the word “Pakistani” and display the result in your browser.
Repeat Q1 using string concat() method.
Write a program to replace the “Hyder” to “Islam” in the word “Hyderabad” and display the result in your browser.
Write a program to replace all occurrences of “and” in the string with “&” and display the result in your browser.
var message = “Ali and Sami are best friends. They play cricket and football together.”;
Write a program that converts a string “472” to a number 472. Display the values & types in your browser.
Write a program that takes user input. Convert and show the input in capital letters.
Write a program that takes user input. Convert and show the input in title case.
Write a program that converts the variable num to string. var num = 35.36 ; Remove the dot to display “3536” display in your browser.
Write a program to take user input and store username in a variable. If the username contains any special symbol among [@ . , !], prompt the user to enter a valid username. For character codes of [@ .
Note:
ASCII code of ! is 33
ASCII code of , is 44
ASCII code of . is 46
ASCII code of @ is 64
You have an array
A = [cake”, “apple pie”, “cookie”, “chips”, “patties”]
Write a program to enable “search by user input” in an array.
After searching, prompt the user whether the given item is found in the list or not.
Note: Perform case insensitive search. Whether the user enters cookie, Cookie, COOKIE or coOkIE, program should inform about its availability.
Example:
Write a program to take password as an input from user.
The password must qualify these requirements:
a. It should contain alphabets and numbers
b. It should not start with a number
c. It must at least 6 characters long If the password does not meet above requirements,
prompt the user to enter a valid password.
For character codes of a-z, A-Z & 0-9, refer to ASCII table at the end of this document.
Write a program to convert the following string to an array using string split method.
var university = “University of Karachi”;
Display the elements of array in your browser.
Write a program to display the last character of a user input.
// You have a string “The quick brown fox jumps over the lazy dog”.
Write a program to count number of occurrences of word “the” in given string.