Randell Dawson e0e6334628
fix(curriculum): Consolidated comments for JavaScript Algorithms and Data Structures challenges - part 3 of 4 (#38264)
* fix: remove example code from challenge seed

* fix: remove declaration from solution

* fix: added sum variable back in

* fix: reverted description back to original version

* fix: added examples to description section

* fix: added complete sentence

Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* fix: corrected typo

Co-Authored-By: Manish Giri <manish.giri.me@gmail.com>

* fix: reverted to original desc with formatted code

* fix: removed unnecessary code example from description section

Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* fix: failiing test on iterate through array with for loop

* fix: changed to Only change this line

Co-Authored-By: Manish Giri <manish.giri.me@gmail.com>

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Manish Giri <manish.giri.me@gmail.com>
Co-authored-by: moT01 <tmondloch01@gmail.com>
2020-03-25 16:07:13 +01:00

1.9 KiB

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

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.js are imported into a file in the same directory:
import * as myMathModule from "./math_functions.js";

The above import statement will create an object called myMathModule. This is just a variable name, you can name it anything. The object will contain all of the exports from math_functions.js in it, so you can access the functions like you would any other object property. Here's how you can use the add and subtract functions that were imported:

myMathModule.add(2,3);
myMathModule.subtract(5,3);

Instructions

The code in this file requires the contents of the file: string_functions.js, that is in the same directory as the current file. Use the import * as syntax to import everything from the file into an object called stringFunctions.

Tests

tests:
  - text: Your code should properly use <code>import * as</code> syntax.
    testString: assert(code.match(/import\s*\*\s*as\s+stringFunctions\s+from\s*('|")\.\/string_functions\.js\1/g));

Challenge Seed


// Only change code above this line

stringFunctions.uppercaseString("hello");
stringFunctions.lowercaseString("WORLD!");

Solution

import * as stringFunctions from "./string_functions.js";

stringFunctions.uppercaseString("hello");
stringFunctions.lowercaseString("WORLD!");