Randell Dawson 05f73ca409 fix(curriculum): Convert blockquote elements to triple backtick syntax for JavaScript Algorithms and Data Structures (#35992)
* fix: convert js algorithms and data structures

* fix: revert some blocks back to blockquote

* fix: reverted comparison code block to blockquotes

* fix: change js to json

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

* fix: convert various section to triple backticks

* fix: Make the formatting consistent for comparisons
2019-05-17 08:20:30 -05:00

1.8 KiB

id, title, challengeType
id title challengeType
587d7b8d367417b2b2512b59 Import a Default Export 1

Description

In the last challenge, you learned about export default and its uses. It is important to note that, to import a default export, you need to use a different import syntax. In the following example, we have a function, add, that is the default export of a file, "math_functions". Here is how to import it:
import add from "math_functions";
add(5,4); // Will return 9

The syntax differs in one key place - the imported value, add, is not surrounded by curly braces, {}. Unlike exported values, the primary method of importing a default export is to simply write the value's name after import.

Instructions

In the following code, please import the default export, subtract, from the file "math_functions", found in the same directory as this file.

Tests

tests:
  - text: You need to properly import <code>subtract</code> from <code>"math_functions"</code>.
    testString: getUserInput => assert(getUserInput('index').match(/import\s+subtract\s+from\s+('|")math_functions\1/g), 'You need to properly import <code>subtract</code> from <code>"math_functions"</code>.');

Challenge Seed

"use strict";
subtract(7,4);

Before Test

self.require = function(str) {
  if (str === 'math_functions') {
    return function(a, b) {
      return a - b;
    }
  }
};

Solution

import subtract from "math_functions";
subtract(7,4);