Write a program to count how many characters are in a given string (without using .length
directly inside the loop).
Hint: Use a loop to go through each character and count them manually.
Sample Input: "Hello"
Sample Output: Total characters: 5
Write a program that reverses a given string.
Hint: Use a loop to add each character to a new string in reverse order.
Sample Input: "World"
Sample Output: "dlroW"
Write a program to count how many vowels (a, e, i, o, u
) are in a given string.
Hint: Use a loop and if
condition to check each character.
Sample Input: "Programming"
Sample Output: Vowels: 3
Write a program to convert a string to uppercase manually (without using .toUpperCase()
inside loop).
Hint: Use .toUpperCase()
once after reading the string.
Sample Input: "hello"
Sample Output: "HELLO"
Write a program to count how many times a given character appears in a string.
Hint: Use a loop and compare each character with the given one.
Sample Input:
String: "banana"
Character: "a"
Sample Output: "a appears 3 times"
Write a program to check whether a string is a palindrome (same forward and backward).
Hint: Compare the string with its reversed version.
Sample Input: "madam"
Sample Output: "Palindrome"
Write a program that prints each character of a string on a new line.
Hint: Use a for
loop to go through the string.
Sample Input: "Code"
Sample Output:
C
o
d
e
Write a program to count how many words are in a sentence.
Hint: Use .split(" ")
to separate words.
Sample Input: "I love JavaScript"
Sample Output: Words: 3
Write a program to replace all spaces in a string with a hyphen (-
).
Hint: Use .replaceAll(" ", "-")
.
Sample Input: "I love JS"
Sample Output: "I-love-JS"
Write a program that prints a given word 5 times using a loop.
Hint: Use for
loop and console.log()
.
Sample Input: "Hello"
Sample Output:
Hello
Hello
Hello
Hello
Hello
Write a program to remove extra spaces from a sentence.
Hint: Use .trim()
and .replaceAll(" ", " ")
.
Sample Input: " Hello JS "
Sample Output: "Hello JS"
Write a program to find the longest word in a sentence.
Hint: Use .split(" ")
and compare lengths using a loop.
Sample Input: "I love programming"
Sample Output: "programming"
Write a program to count how many digits (0–9) are in a given string.
Hint: Use a loop and if
to check if a character is between '0'
and '9'
.
Sample Input: "abc123xyz45"
Sample Output: Digits: 5
Write a program to remove all vowels from a string.
Hint: Use .replaceAll()
or a loop to skip vowels.
Sample Input: "Hello"
Sample Output: "Hll"
Write a program that prints every substring of a given string using loop and .slice()
.
Hint: Use for
loop and slice from 0 to i.
Sample Input: "JS"
Sample Output:
J
JS