0
0
Typescriptprogramming~10 mins

Namespace declaration 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 namespace named MyNamespace.

Typescript
namespace [1] {
  export const greeting = "Hello";
}
Drag options to blanks, or click blank then click option'
ANamespace
BMyNamespace
CmyNamespace
DNamespace1
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or different casing for the namespace name.
Using reserved words like 'Namespace' as the name.
2fill in blank
medium

Complete the code to access the greeting constant inside the MyNamespace namespace.

Typescript
console.log([1].greeting);
Drag options to blanks, or click blank then click option'
AGreeting
Bnamespace
CMyNamespace
DmyNamespace
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing for the namespace name.
Trying to access the member without the namespace prefix.
3fill in blank
hard

Fix the error in the namespace declaration by completing the code.

Typescript
namespace [1] {
  export function greet() {
    return "Hi!";
  }
}
Drag options to blanks, or click blank then click option'
AMyNamespace
Bnamespace
CmyNamespace
DGreetNamespace
Attempts:
3 left
💡 Hint
Common Mistakes
Using reserved words as namespace names.
Using inconsistent casing.
4fill in blank
hard

Fill both blanks to declare a namespace Utils with a constant version set to 1.0.

Typescript
namespace [1] {
  export const [2] = 1.0;
}
Drag options to blanks, or click blank then click option'
AUtils
BVersion
Cversion
Dutils
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase for the constant name.
Using lowercase for the namespace name.
5fill in blank
hard

Fill all three blanks to declare a namespace MathOps with a function add that returns the sum of two numbers a and b.

Typescript
namespace [1] {
  export function [2](a: number, b: number): number {
    return a [3] b;
  }
}
Drag options to blanks, or click blank then click option'
AMathOps
Badd
C+
Dsubtract
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong operator like '-' instead of '+'.
Naming the function incorrectly.