0
0
Typescriptprogramming~10 mins

Namespace merging 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 'Shapes'.

Typescript
namespace [1] {
  export const pi = 3.14;
}
Drag options to blanks, or click blank then click option'
AShapes
BMath
CCircle
DGeometry
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than 'Shapes' causes the namespace to be unrelated.
Forgetting to use the 'namespace' keyword.
2fill in blank
medium

Complete the code to add a function 'area' inside the 'Shapes' namespace.

Typescript
namespace Shapes {
  export const pi = 3.14;
  export function [1](radius: number): number {
    return pi * radius * radius;
  }
}
Drag options to blanks, or click blank then click option'
Acircumference
Barea
Cperimeter
Dvolume
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name like 'circumference' or 'volume'.
Not exporting the function to make it accessible outside.
3fill in blank
hard

Fix the error in merging two namespaces named 'Shapes'.

Typescript
namespace Shapes {
  export const pi = 3.14;
}

namespace Shapes {
  export function [1](radius: number): number {
    return Shapes.pi * radius * radius;
  }
}
Drag options to blanks, or click blank then click option'
Aarea
Bradius
Cdiameter
Dcircumference
Attempts:
3 left
💡 Hint
Common Mistakes
Using different namespace names prevents merging.
Naming the function incorrectly.
4fill in blank
hard

Fill both blanks to create a merged namespace 'Shapes' with a constant and a function.

Typescript
namespace [1] {
  export const [2] = 3.14;
}

namespace Shapes {
  export function area(radius: number): number {
    return Shapes.pi * radius * radius;
  }
}
Drag options to blanks, or click blank then click option'
AShapes
BCircle
Cpi
Dradius
Attempts:
3 left
💡 Hint
Common Mistakes
Using different namespace names prevents merging.
Using a wrong constant name breaks the calculation.
5fill in blank
hard

Fill all three blanks to create a merged namespace 'Shapes' with a constant, a function, and a nested namespace.

Typescript
namespace [1] {
  export const [2] = 3.14;
  export function area(radius: number): number {
    return pi * radius * radius;
  }
  export namespace [3] {
    export function circumference(radius: number): number {
      return 2 * Shapes.pi * radius;
    }
  }
}
Drag options to blanks, or click blank then click option'
AShapes
Bpi
CCircle
DGeometry
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names breaks the namespace structure.
Forgetting to export nested namespaces or constants.