fix/add-tests

This commit is contained in:
moT01 2019-05-30 09:04:11 -05:00 committed by Kristofer Koishigawa
parent 8a579210e3
commit 8b5cc6d277
2 changed files with 28 additions and 15 deletions

View File

@ -1,12 +1,12 @@
---
id: 5cddbfd622f1a59093ec611d
title: Create a Module Script
challengeType: 1
challengeType: 6
---
## Description
<section id='description'>
Javascript started with a small role to play on an otherwise mostly html internet. Today, its huge, and some websites are built almost entirely with javascript. In order to make javascript more modular, clean, and maintainable, ES6 introduced a way easily share code amongst javascript files. This involves exporting parts of a javascript file for use in one or more other files, and importing the parts you need to each file. In order to take advantage of this functionality, you need to create a script in your html file with a type of <code>module</code>. Heres an example:
Javascript started with a small role to play on an otherwise mostly html internet. Today, its huge, and some websites are built almost entirely with javascript. In order to make javascript more modular, clean, and maintainable, ES6 introduced a way to easily share code among javascript files. This involves exporting parts of a javascript file for use in one or more other files, and importing the parts you need, where you need them. In order to take advantage of this functionality, you need to create a script in your html document with a type of <code>module</code>. Heres an example:
```html
<script type="module" src="filename.js"></script>
@ -26,36 +26,49 @@ Add a script to the html document of type <code>module</code> and give it the so
```yml
tests:
- text: <code>var</code> should not exist in code.
testString: getUserInput => assert(!getUserInput('index').match(/var/g),'<code>var</code> should not exist in code.');
- text: You should create a <code>script</code> tag.
testString: assert(code.match(/<\s*script[^>]*>\s*<\/\s*script\s*>/g));
- text: Your <code>script</code> tag should be of type <code>module</code>.
testString: assert(code.match(/<\s*script\s*[^t]*type\s*=\s*('|")module\1[^>]*>\s*<\/\s*script\s*>/g));
- text: Your <code>script</code> tag should have a <code>src</code> of <code>index.js</code>.
testString: assert(code.match(/<\s*script\s*[^s]*src\s*=\s*('|")index\.js\1[^>]*>\s*<\/\s*script\s*>/g));
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
<div id='html-seed'>
```html
<html>
// add your code below
// add your code above
<html>
<body>
<!-- add your code below -->
<!-- add your code above -->
</body>
</html>
```
</div>
</section>
## Solution
<section id='solution'>
```html
<html>
// add your code below
// add your code above
<html>
<body>
<!-- add your code below -->
<script type="module" src="main.js"></script>
<!-- add your code above -->
</body>
</html>
```
</section>

View File

@ -6,7 +6,7 @@ challengeType: 1
## Description
<section id='description'>
Imagine you have a function, <code>capitalizeFirstLetter</code>, that simply takes in a string, and returns the string with the first letter capitalized. You want to use this function in three different javascript files. In order to share the function with the files, you need to first <code>export</code> it.
Imagine you have a function, <code>capitalizeFirstLetter</code>, that simply takes in a string and returns the string with the first letter capitalized. You want to use this function in several different javascript files. In order to share the function with the files, you need to first <code>export</code> it.
```js
export const capitalizeFirstLetter = (string) => {
@ -24,6 +24,7 @@ const capitalizeFirstLetter = (string) => {
export { capitalizeFirstLetter };
```
After you export a function like this, you can import it in another file to use without having to rewrite the function.
</section>
## Instructions
@ -52,8 +53,7 @@ tests:
```js
"use strict";
const foo = "bar";
const bar = "foo";
```
</div>