0
0
Typescriptprogramming~20 mins

String manipulation types (Uppercase, Lowercase) in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Case Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this TypeScript code?

Consider this code snippet that changes the case of a string:

const greeting = "Hello World";
const result = greeting.toUpperCase();
console.log(result);

What will be printed to the console?

Typescript
const greeting = "Hello World";
const result = greeting.toUpperCase();
console.log(result);
A"HELLO WORLD"
B"hello world"
C"Hello World"
D"HeLLo WoRLD"
Attempts:
2 left
💡 Hint

Think about what toUpperCase() does to each letter.

Predict Output
intermediate
2:00remaining
What is the output of this TypeScript code?

Look at this code that changes string case:

const text = "TypeScript";
const lower = text.toLowerCase();
console.log(lower);

What will be printed to the console?

Typescript
const text = "TypeScript";
const lower = text.toLowerCase();
console.log(lower);
A"TYPESCRIPT"
B"typescript"
C"TypeScript"
D"TyPeScRiPt"
Attempts:
2 left
💡 Hint

Remember what toLowerCase() does.

Predict Output
advanced
2:00remaining
What is the output of this TypeScript code with mixed case methods?

Check this code that uses both uppercase and lowercase methods:

const phrase = "JavaScript Rocks!";
const part1 = phrase.substring(0, 10).toLowerCase();
const part2 = phrase.substring(10).toUpperCase();
console.log(part1 + part2);

What will be printed to the console?

Typescript
const phrase = "JavaScript Rocks!";
const part1 = phrase.substring(0, 10).toLowerCase();
const part2 = phrase.substring(10).toUpperCase();
console.log(part1 + part2);
A"javascript ROCKS!"
B"JAVASCRIPT rocks!"
C"javascript rocks!"
D"JavaScript ROCKS!"
Attempts:
2 left
💡 Hint

Look carefully at how substring and case methods combine.

Predict Output
advanced
2:00remaining
What is the output of this TypeScript code using chaining?

Observe this code that chains string methods:

const input = "  Mixed CASE String  ";
const output = input.trim().toLowerCase().replace(/ /g, "_");
console.log(output);

What will be printed to the console?

Typescript
const input = "  Mixed CASE String  ";
const output = input.trim().toLowerCase().replace(/ /g, "_");
console.log(output);
A"Mixed_CASE_String"
B"MIXED_CASE_STRING"
C"mixed_case_string"
D"mixed CASE String"
Attempts:
2 left
💡 Hint

Think about what each method does step by step.

🧠 Conceptual
expert
2:00remaining
Which option will cause a runtime error in TypeScript when manipulating string cases?

Consider these four code snippets. Only one will cause a runtime error when run. Which one is it?

A
const s: string = "hello";
console.log(s.toLowerCase());
B
const s: string | undefined = undefined;
console.log(s?.toLowerCase());
C
const s: string | null = null;
console.log(s?.toUpperCase());
D
const s: any = 123;
console.log(s.toUpperCase());
Attempts:
2 left
💡 Hint

Think about what happens if you call a string method on a non-string value.