Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f5971e

Browse files
committed
init: lesson 1 complete
0 parents  commit1f5971e

File tree

14 files changed

+427
-0
lines changed

14 files changed

+427
-0
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to[Semantic Versioning](http://semver.org/).
4+
5+
##[0.1.0]
6+
- First release

‎README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ES2015
2+
3+
Practice refactoring with ES2015 features.
4+
5+
6+
##CodeRoad
7+
8+
CodeRoad is an open-sourced interactive tutorial platform for the Atom Editor. Learn more at[CodeRoad.io](http://coderoad.io).
9+
10+
11+
##Setup
12+
13+
* install the tutorial package
14+
15+
`npm install --save coderoad-es2015`
16+
17+
* install and run the[atom-coderoad](https://github.com/coderoad/atom-coderoad) plugin
18+
19+
20+
##Outline
21+
22+
###Declaring Variables
23+
24+
Using`let` &`const`.
25+
26+
#####Let
27+
28+
`let` allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.
29+
30+
This is unlike the`var` keyword, which defines a variable globally, or locally to an entire function regardless of block scope.
31+
32+
```js
33+
varglobal=true;
34+
let blockScoped=true;
35+
```
36+
37+
#####Const
38+
39+
Writing basic functions continued.
40+
41+
We'll write two more basic functions, this time without any help.

‎coderoad.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"info": {
3+
"title":"ES2015",
4+
"description":"Practice refactoring with ES2015 features."
5+
},
6+
"chapters": [
7+
{
8+
"title":"Declaring Variables",
9+
"description":"Using `let` & `const`.",
10+
"pages": [
11+
{
12+
"title":"Let",
13+
"description":"`let` allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.\n\nThis is unlike the `var` keyword, which defines a variable globally, or locally to an entire function regardless of block scope.\n\n```js\nvar global = true;\nlet blockScoped = true;\n```",
14+
"tasks": [
15+
{
16+
"description":"Run the `varTest` function and look in the console.",
17+
"tests": [
18+
"1/01/01"
19+
],
20+
"hints": [
21+
"Click\"SAVE\". ⌘ + S on Mac, ctrl + S on Windows"
22+
],
23+
"actions": [
24+
"open('let.js')",
25+
"set('// call `varTest()`\nfunction varTest() {\n\tvar x = 1;\n\tif (true) {\n\t\tvar x = 2;\n\t\tconsole.log(x);\n\t}\n\tconsole.log(x);\n}\nvarTest();\n\n')"
26+
]
27+
},
28+
{
29+
"description":"Change `var` to `let` and run the `letTest` function. Don't forget to look in the console.",
30+
"tests": [
31+
"1/01/02"
32+
],
33+
"actions": [
34+
"insert('\n// use `let` and call `letTest()`\nfunction letTest() {\n\tvar x = 3;\n\tif (true) {\n\t\tvar x = 4;\n\t\tconsole.log(x);\n\t}\n\tconsole.log(x);\n}\nletTest();\n\n')"
35+
]
36+
},
37+
{
38+
"description":"fix the for loop to log numbers from 1 to 5",
39+
"tests": [
40+
"1/01/03"
41+
],
42+
"actions": [
43+
"insert('\n// log numbers from 1 to 5\nfor (var i = 1; i <= 5 ; i++ ) {\n setTimeout(function() {\n console.log(i);\n })\n}\n// 6 6 6 6 6\n\n')"
44+
]
45+
}
46+
],
47+
"onPageComplete":"Great! Now you that you have an idea of how `let` works, continue to look at declaring variables with `const`."
48+
},
49+
{
50+
"title":"Const",
51+
"description":"Writing basic functions continued.\n\nWe'll write two more basic functions, this time without any help.",
52+
"tasks": [
53+
{
54+
"description":"write a function `divideOne` divides a number by 1",
55+
"tests": [
56+
"1/02/01"
57+
],
58+
"actions": [
59+
"open('page-02.js')",
60+
"set('// divideOne\nfunction divideOne(x) {\n return ::>\n}\n')"
61+
]
62+
},
63+
{
64+
"description":"write a function `mutiplyone` that multiplies a number by 1",
65+
"tests": [
66+
"1/02/02"
67+
],
68+
"actions": [
69+
"insert('\n// multiplyOne\nfunction multiplyOne(x) {\n return ::>\n}\n')"
70+
]
71+
}
72+
]
73+
}
74+
]
75+
}
76+
]
77+
}

‎package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name":"coderoad-es2015",
3+
"version":"0.1.0",
4+
"description":"Coderoad tutorial",
5+
"author":"Name <email> (site)",
6+
"contributors": [],
7+
"main":"coderoad.json",
8+
"files": [
9+
"coderoad.json",
10+
"tutorial"
11+
],
12+
"keywords": [
13+
"coderoad",
14+
"tutorial"
15+
],
16+
"engines": {
17+
"node":">=0.10.3"
18+
},
19+
"dependencies": {
20+
"mocha-coderoad":"^0.6.0",
21+
"chai-spies":"0.7.1",
22+
"chai":"3.5.0"
23+
},
24+
"license":"MIT",
25+
"config": {
26+
"dir":"tutorial",
27+
"runner":"mocha-coderoad",
28+
"testSuffix":".spec.js"
29+
}
30+
}

‎tutorial/1/01/01.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
varchai=require('chai');
3+
varspies=require('chai-spies');
4+
varexpect=chai.expect;
5+
chai.use(spies);
6+
varspy=chai.spy.on(console,'log');
7+
8+
/// load('let.js')
9+
10+
describe('01 varTest',function(){
11+
12+
it('doesn\'t exist',function(){
13+
expect(varTest).to.be.defined;
14+
});
15+
16+
it('hasn\'t been called',function(){
17+
expect(spy.__spy.calls[0][0]).to.equal(2);
18+
expect(spy.__spy.calls[1][0]).to.equal(2);
19+
});
20+
21+
});

‎tutorial/1/01/02.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
describe('02 letTest',function(){
2+
3+
it('doesn\'t exist',function(){
4+
expect(letTest).to.be.defined;
5+
});
6+
7+
it('should use `let` instead of `var`',function(){
8+
console.log('spy',spy);
9+
expect(spy).to.have.been.called.with(4);
10+
});
11+
12+
it('isn\'t calling 4 & 3',function(){
13+
expect(spy.__spy.calls[2][0]).to.equal(4);
14+
expect(spy.__spy.calls[3][0]).to.equal(3);
15+
});
16+
17+
});

‎tutorial/1/01/03.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
describe('03 the for loop',function(){
2+
3+
it('isn\'t logging from 1 to 5',function(){
4+
expect(spy.__spy.calls[4][0]).to.equal(1);
5+
expect(spy.__spy.calls[8][0]).to.equal(5);
6+
});
7+
8+
});

‎tutorial/1/01/let.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
###Let
2+
3+
`let` allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.
4+
5+
This is unlike the`var` keyword, which defines a variable globally, or locally to an entire function regardless of block scope.
6+
7+
```js
8+
varglobal=true;
9+
let blockScoped=true;
10+
```
11+
12+
13+
+ Run the`varTest` function and look in the console.
14+
@test('1/01/01')
15+
@hint('Click "SAVE". ⌘ + S on Mac, ctrl + S on Windows')
16+
@action(open('let.js'))
17+
@action(set(
18+
```
19+
// call `varTest()`
20+
function varTest() {
21+
var x = 1;
22+
if (true) {
23+
var x = 2;
24+
console.log(x);
25+
}
26+
console.log(x);
27+
}
28+
varTest();
29+
30+
```
31+
))
32+
33+
+ Change`var` to`let` and run the`letTest` function. Don't forget to look in the console.
34+
@test('1/01/02')
35+
@action(insert(
36+
```
37+
38+
// use `let` and call `letTest()`
39+
function letTest() {
40+
var x = 3;
41+
if (true) {
42+
var x = 4;
43+
console.log(x);
44+
}
45+
console.log(x);
46+
}
47+
letTest();
48+
49+
```
50+
))
51+
52+
+ fix the for loop to log numbers from 1 to 5
53+
@test('1/01/03')
54+
@action(insert(
55+
```
56+
57+
// log numbers from 1 to 5
58+
for (var i = 1; i <= 5 ; i++ ) {
59+
setTimeout(function() {
60+
console.log(i);
61+
})
62+
}
63+
// 6 6 6 6 6
64+
65+
```
66+
))
67+
68+
@onPageComplete('Great! Now you that you have an idea of how`let` works, continue to look at declaring variables with`const`.')

‎tutorial/1/02/01.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
varexpect=require('chai').expect;
2+
3+
// load('page-02.js')
4+
5+
describe('01 divideOne',function(){
6+
7+
it('doesn\'t exist',function(){
8+
expect(divideOne).to.be.defined;
9+
});
10+
11+
it('should take a parameter',function(){
12+
expect(divideOne).to.have.length(1);
13+
});
14+
15+
it('doesn\'t output a number',function(){
16+
expect(divideOne(1)).to.be.a('number');
17+
});
18+
19+
it('returns the same number',function(){
20+
expect(divideOne(1)).to.equal(1);
21+
expect(divideOne(10)).to.equal(10);
22+
});
23+
24+
});

‎tutorial/1/02/02.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
describe('02 multiplyOne',function(){
2+
3+
it('doesn\'t exist',function(){
4+
expect(multiplyOne).to.be.defined;
5+
});
6+
7+
it('should take a parameter',function(){
8+
expect(multiplyOne).to.have.length(1);
9+
});
10+
11+
it('should output a number',function(){
12+
expect(multiplyOne(1)).to.be.a('number');
13+
});
14+
15+
it('returns the multiplied number by one',function(){
16+
expect(multiplyOne(1)).to.equal(1);
17+
expect(multiplyOne(10)).to.equal(10);
18+
});
19+
20+
});

‎tutorial/1/02/const.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
###Const
2+
Writing basic functions continued.
3+
4+
We'll write two more basic functions, this time without any help.
5+
6+
+ write a function`divideOne` divides a number by 1
7+
@test('1/02/01')
8+
@action(open('page-02.js'))
9+
@action(set(
10+
```
11+
// divideOne
12+
function divideOne(x) {
13+
return ::>
14+
}
15+
```
16+
))
17+
18+
+ write a function`mutiplyone` that multiplies a number by 1
19+
@test('1/02/02')
20+
@action(insert(
21+
```
22+
23+
// multiplyOne
24+
function multiplyOne(x) {
25+
return ::>
26+
}
27+
```
28+
))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp