Skip to content

Commit c098f72

Browse files
committed
Switch to mocha with jsdom
1 parent d4edee0 commit c098f72

8 files changed

+160
-49
lines changed

.#beatles.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pletcher@pletcher.local.331

.gitignore

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
# Created by https://www.gitignore.io/api/node
3+
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
15+
# Directory for instrumented libs generated by jscoverage/JSCover
16+
lib-cov
17+
18+
# Coverage directory used by tools like istanbul
19+
coverage
20+
21+
# nyc test coverage
22+
.nyc_output
23+
24+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
25+
.grunt
26+
27+
# node-waf configuration
28+
.lock-wscript
29+
30+
# Compiled binary addons (http://nodejs.org/api/addons.html)
31+
build/Release
32+
33+
# Dependency directories
34+
node_modules
35+
jspm_packages
36+
37+
# Optional npm cache directory
38+
.npm
39+
40+
# Optional REPL history
41+
.node_repl_history
42+
43+
.results.json

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77

88
## Instructions
99

10-
Make sure you run the tests with `learn -b` to get the full output in the browser.
10+
Make sure you run the tests with `learn`.
1111

1212
+ Create a function `theBeatlesPlay`, which accepts two parameters- an array of musicians and an array of instruments. The body of the function should create an empty array stored in a variable. The function should also contain a for loop which loops over the array of musicians. You'll want to be careful about what value you set your counter variable to store. (Hint: Think about what the first index of an array is). The first time through the loop, the body of the loop should create a string using the first index of the musicians array and the first index of the instruments array: `"John Lennon plays guitar"`. This string should be added to the empty array you created. The loop should make the same sentence for every member of the musicians array. The function should return the array of new strings.
1313

1414
+ Create a function `johnLennonFacts`. Inside the function, create an array which contains facts about John Lennon:
1515

1616
```js
17-
facts = ["He was the last Beatle to learn to drive", "He was never a vegetarian", "He was a choir boy and boy scout", "He hated the sound of his own voice"];
17+
const facts = [
18+
"He was the last Beatle to learn to drive",
19+
"He was never a vegetarian",
20+
"He was a choir boy and boy scout",
21+
"He hated the sound of his own voice"
22+
];
1823
```
1924

2025
The function should also create a second variable that stores an empty array. Use a while loop to loop over the facts array and add `"!!!"` to the end of every fact. The new string with the exclamation points should be added to the empty array.

beatles.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
'use strict';
1+
function theBeatlesPlay(musicians, instruments) {
2+
const arr = []
3+
4+
for (let i = 0, l = musicians.length; i < l; i++) {
5+
arr.push(`${musicians[i]} plays ${instruments[i]}`)
6+
}
7+
8+
return arr
9+
}
10+
11+
function johnLennonFacts() {
12+
const facts = [
13+
"He was the last Beatle to learn to drive",
14+
"He was never a vegetarian",
15+
"He was a choir boy and boy scout",
16+
"He hated the sound of his own voice"
17+
]
18+
19+
const shoutedFacts = []
20+
21+
let i = 0
22+
while (i < facts.length) {
23+
shoutedFacts.push(`${facts[i]}!!!`)
24+
i++
25+
}
26+
27+
return shoutedFacts
28+
}
29+
30+
function iLoveTheBeatles(n) {
31+
const arr = []
32+
33+
do {
34+
arr.push('I love the Beatles!')
35+
n++
36+
} while (n < 15)
37+
38+
return arr
39+
}

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "js-beatles-loops-lab",
3+
"version": "0.1.0",
4+
"description": "JavaScript for Beatles Fans",
5+
"main": "beatles.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"scripts": {
10+
"test": "mocha -R mocha-multi --reporter-options nyan=-,json=.results.json"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/learn-co-curriculum/js-beatles-loops-lab.git"
15+
},
16+
"keywords": [
17+
"javascript",
18+
"beatles",
19+
"flatiron",
20+
"loops"
21+
],
22+
"author": "@vicfriedman",
23+
"license": "SEE LICENSE IN LICENSE.md",
24+
"bugs": {
25+
"url": "https://github.com/learn-co-curriculum/js-beatles-loops-lab/issues"
26+
},
27+
"homepage": "https://github.com/learn-co-curriculum/js-beatles-loops-lab#readme",
28+
"devDependencies": {
29+
"chai": "^3.5.0",
30+
"jsdom": "^9.0.0",
31+
"mocha": "^2.4.5",
32+
"mocha-jsdom": "^1.1.0",
33+
"mocha-multi": "^0.9.0"
34+
}
35+
}

requires.yml

-5
This file was deleted.

spec/beatles_spec.js

-41
This file was deleted.

test/beatles-test.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*global beforeEach, describe, it */
2+
3+
const expect = require('chai').expect
4+
const fs = require('fs')
5+
const jsdom = require('mocha-jsdom')
6+
const path = require('path')
7+
8+
describe('theBeatlesPlay', () => {
9+
jsdom({
10+
src: fs.readFileSync(path.resolve(__dirname, '..', 'beatles.js'), 'utf-8')
11+
})
12+
13+
it("returns an array of strings containing what instruments each instrument plays", () => {
14+
const musicians = ["John Lennon", "Paul McCartney", "George Harrison", "Ringo Starr"];
15+
const instruments = ["Guitar", "Bass Guitar", "Lead Guitar", "Drums"];
16+
17+
expect(theBeatlesPlay(musicians, instruments)).to.eql(["John Lennon plays Guitar", "Paul McCartney plays Bass Guitar", "George Harrison plays Lead Guitar", "Ringo Starr plays Drums"]);
18+
});
19+
20+
describe('johnLennonFacts', () => {
21+
it("returns an array of strings with exclamation points", () => {
22+
expect(johnLennonFacts()).to.eql(["He was the last Beatle to learn to drive!!!", "He was never a vegetarian!!!", "He was a choir boy and boy scout!!!", "He hated the sound of his own voice!!!"]);
23+
});
24+
});
25+
26+
describe('iLoveTheBeatles', () => {
27+
it("returns an array of 'I love the Beatles!' 8 times when passed the parameter 7 ", () => {
28+
expect(iLoveTheBeatles(7)).to.eql(["I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!", "I love the Beatles!"]);
29+
});
30+
31+
it("returns an array of 'I love the Beatles!' once when passed the parameter 17", () => {
32+
expect(iLoveTheBeatles(17)).to.eql(["I love the Beatles!"]);
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)