0
0
Typescriptprogramming~10 mins

Static members with types 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 static property named count of type number.

Typescript
class Counter {
  static [1]: number = 0;
}
Drag options to blanks, or click blank then click option'
Avalue
Bcount
Ctotal
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using instance property syntax instead of static
Choosing wrong property name
2fill in blank
medium

Complete the code to declare a static method named getCount that returns a number.

Typescript
class Counter {
  static count: number = 0;
  static [1](): number {
    return Counter.count;
  }
}
Drag options to blanks, or click blank then click option'
AsetCount
Bcount
CcountValue
DgetCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using instance method syntax
Wrong method name
3fill in blank
hard

Fix the error in the static method declaration to correctly access the static property count.

Typescript
class Counter {
  static count: number = 0;
  static getCount(): number {
    return [1].count;
  }
}
Drag options to blanks, or click blank then click option'
ACounter
Binstance
Cself
Dthis
Attempts:
3 left
💡 Hint
Common Mistakes
Using this to access static properties
Using undefined identifiers
4fill in blank
hard

Fill both blanks to declare a static readonly property named MAX_LIMIT of type number with value 100.

Typescript
class Limit {
  [1] readonly [2]: number = 100;
}
Drag options to blanks, or click blank then click option'
Areadonly
Bstatic
CMAX_LIMIT
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping order of keywords
Using wrong property name
5fill in blank
hard

Fill all three blanks to declare a static method named increment that increases the static count by 1 and returns the new count.

Typescript
class Counter {
  static count: number = 0;
  static [1](): number {
    Counter.count [2]= 1;
    return [3];
  }
}
Drag options to blanks, or click blank then click option'
Aincrement
B+
CCounter.count
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operator like -=
Returning wrong variable