Complete the code to convert the string to uppercase.
const text = "hello"; const upperText = text.[1](); console.log(upperText);
The toUpperCase() method converts all characters in a string to uppercase.
Complete the code to convert the string to lowercase.
const text = "WORLD"; const lowerText = text.[1](); console.log(lowerText);
The toLowerCase() method converts all characters in a string to lowercase.
Fix the error in the code to convert the string to uppercase.
const greeting = "hello world"; const shout = greeting.[1](); console.log(shout);
The correct method name is toUpperCase() with exact casing.
Fill both blanks to create a new string with the first letter uppercase and the rest lowercase.
const word = "jAVAscript"; const fixed = word.charAt(0).[1]() + word.[2](1).toLowerCase(); console.log(fixed);
charAt(0).toUpperCase() capitalizes the first letter, and slice(1).toLowerCase() lowercases the rest.
Fill all three blanks to create a function that capitalizes the first letter of a string and makes the rest lowercase.
function capitalize(str: string): string {
return str.[1](0).[2]() + str.[3](1).toLowerCase();
}substring instead of slice (both work but slice is preferred here)toUpperCase() as a functionThe function gets the first character with charAt(0), converts it to uppercase with toUpperCase(), then adds the rest of the string sliced from index 1 with slice(1) converted to lowercase.