Aly Pilkons dae22c95c3 Edit Instructions Text To Make Goal Clearer (#35887)
* Edit Instructions Text To Make Goal Clearer

The instructions end with "using the object provided" which is unclear since the user is expected to create their own name for the object. Users may think they need to reference an object name and be confused when they do not find it. Reiterating that the user needs to create the name for the object themselves makes the task clearer.

* Updated commit based on comments
2019-04-26 18:33:04 +05:30

2.0 KiB

id, title, challengeType
id title challengeType
587d7b8c367417b2b2512b57 Use * to Import Everything from a File 1

Description

Suppose you have a file and you wish to import all of its contents into the current file. This can be done with the import * as syntax. Here's an example where the contents of a file named "math_functions" are imported into a file in the same directory:
import * as myMathModule from "math_functions";
myMathModule.add(2,3);
myMathModule.subtract(5,3);
And breaking down that code:
import * as object_with_name_of_your_choice from "file_path_goes_here"
object_with_name_of_your_choice.imported_function
You may use any name following the import * as portion of the statement. In order to utilize this method, it requires an object that receives the imported values (i.e., you must provide a name). From here, you will use the dot notation to call your imported values.

Instructions

The code in this file requires the contents of another file, "capitalize_strings", that is in the same directory as the current file. Add the appropriate import * as statement to the top of the file.

Tests

tests:
  - text: Properly uses <code>import * as</code> syntax.
    testString: assert(code.match(/import\s+\*\s+as\s+[a-zA-Z0-9_$]+\s+from\s*"\s*capitalize_strings\s*"\s*;/gi), 'Properly uses <code>import * as</code> syntax.');

Challenge Seed

"use strict";

Before Test

self.require = function(str) {
  if (str === 'capitalize_strings') {
    return {
      capitalize: str => str.toUpperCase(),
      lowercase: str => str.toLowerCase()
    }
  }
};

Solution

import * as capitalize_strings from "capitalize_strings";