Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or different casing for the namespace name.
Using reserved words like 'Namespace' as the name.
✗ Incorrect
The keyword
namespace is followed by the exact name of the namespace, which is MyNamespace here.2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing for the namespace name.
Trying to access the member without the namespace prefix.
✗ Incorrect
To access a member inside a namespace, use the namespace name followed by a dot and the member name.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using reserved words as namespace names.
Using inconsistent casing.
✗ Incorrect
Namespace names should be valid identifiers and follow the naming convention used in the rest of the code.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase for the constant name.
Using lowercase for the namespace name.
✗ Incorrect
The namespace name is
Utils and the constant inside is named version with lowercase 'v'.5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong operator like '-' instead of '+'.
Naming the function incorrectly.
✗ Incorrect
The namespace is
MathOps, the function is named add, and the operator for addition is +.