0
0
Typescriptprogramming~10 mins

String type behavior in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a string variable with the value 'hello'.

Typescript
let greeting: string = [1];
Drag options to blanks, or click blank then click option'
A`hello`
Bhello
C'hello'
D"hello"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around the string value.
Using backticks when not needed.
2fill in blank
medium

Complete the code to get the length of the string stored in variable 'name'.

Typescript
let length: number = name[1];
Drag options to blanks, or click blank then click option'
A.count
B.length
C.size
D.length()
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses like a function call (e.g., length()).
Using .size or .count which are not string properties.
3fill in blank
hard

Fix the error in the code to convert the string 'text' to uppercase.

Typescript
let upper = text[1];
Drag options to blanks, or click blank then click option'
A.toUpperCase()
B.toUppercase()
C.uppercase()
D.upperCase()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'c' in toUppercase().
Using methods that don't exist like uppercase() or upperCase().
4fill in blank
hard

Fill both blanks to create a string that repeats 'ha' 3 times.

Typescript
let laugh = [1].repeat([2]);
Drag options to blanks, or click blank then click option'
A"ha"
B3
C2
D'ha'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes inconsistently.
Repeating the string the wrong number of times.
5fill in blank
hard

Fill all three blanks to create a new string with the first letter capitalized and the rest lowercase.

Typescript
let newStr = str[1](0, 1).[2]() + str[3](1).toLowerCase();
Drag options to blanks, or click blank then click option'
A.slice
B.toUpperCase
C.substring
D.substr
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice instead of substring (both work but here substring is expected).
Forgetting parentheses after toUpperCase.
Using substr which is deprecated.