Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pletcher committed May 5, 2016
0 parents commit 941573b
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
end_of_line = lf
indent_style = space
insert_final_newline = true

[*{.java,.py}]
indent_size = 4

[*.{js,json,rb}]
charset = utf-8
indent_size = 2
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
6 changes: 6 additions & 0 deletions .learn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tags:
- javascript
languages:
- javascript
resources:
- 1
145 changes: 145 additions & 0 deletions .results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"stats": {
"suites": 6,
"tests": 7,
"passes": 4,
"pending": 0,
"failures": 3,
"start": "2016-05-05T17:04:01.360Z",
"end": "2016-05-05T17:04:01.981Z",
"duration": 621
},
"tests": [
{
"title": "returns my animal",
"fullTitle": "index myAnimal() returns my animal",
"duration": 1,
"currentRetry": 0,
"err": {}
},
{
"title": "returns your animal",
"fullTitle": "index yourAnimal() returns your animal",
"duration": 2,
"currentRetry": 0,
"err": {
"message": "expected 'dog' to equal 'cat'",
"showDiff": true,
"actual": "dog",
"expected": "cat",
"stack": "AssertionError: expected 'dog' to equal 'cat'\n at Context.it (test/index-test.js:23:31)"
}
},
{
"title": "does not hard-code the answer",
"fullTitle": "index yourAnimal() does not hard-code the answer",
"duration": 1,
"currentRetry": 0,
"err": {}
},
{
"title": "adds two to n",
"fullTitle": "index add2(n) adds two to n",
"duration": 0,
"currentRetry": 0,
"err": {
"stack": "ReferenceError: two is not defined\n at add2 (about:blank:15:14)\n at Context.it (test/index-test.js:34:14)",
"message": "two is not defined"
}
},
{
"title": "returns a function",
"fullTitle": "index funkyFunction() returns a function",
"duration": 0,
"currentRetry": 0,
"err": {}
},
{
"title": "is \"FUNKY!\"",
"fullTitle": "index theFunk is \"FUNKY!\"",
"duration": 0,
"currentRetry": 0,
"err": {
"message": "expected [Function] to equal 'FUNKY!'",
"showDiff": true,
"expected": "FUNKY!",
"stack": "AssertionError: expected [Function] to equal 'FUNKY!'\n at Context.it (test/index-test.js:46:26)"
}
},
{
"title": "does not hard-code the answer",
"fullTitle": "index theFunk does not hard-code the answer",
"duration": 0,
"currentRetry": 0,
"err": {}
}
],
"pending": [],
"failures": [
{
"title": "returns your animal",
"fullTitle": "index yourAnimal() returns your animal",
"duration": 2,
"currentRetry": 0,
"err": {
"message": "expected 'dog' to equal 'cat'",
"showDiff": true,
"actual": "dog",
"expected": "cat",
"stack": "AssertionError: expected 'dog' to equal 'cat'\n at Context.it (test/index-test.js:23:31)"
}
},
{
"title": "adds two to n",
"fullTitle": "index add2(n) adds two to n",
"duration": 0,
"currentRetry": 0,
"err": {
"stack": "ReferenceError: two is not defined\n at add2 (about:blank:15:14)\n at Context.it (test/index-test.js:34:14)",
"message": "two is not defined"
}
},
{
"title": "is \"FUNKY!\"",
"fullTitle": "index theFunk is \"FUNKY!\"",
"duration": 0,
"currentRetry": 0,
"err": {
"message": "expected [Function] to equal 'FUNKY!'",
"showDiff": true,
"expected": "FUNKY!",
"stack": "AssertionError: expected [Function] to equal 'FUNKY!'\n at Context.it (test/index-test.js:46:26)"
}
}
],
"passes": [
{
"title": "returns my animal",
"fullTitle": "index myAnimal() returns my animal",
"duration": 1,
"currentRetry": 0,
"err": {}
},
{
"title": "does not hard-code the answer",
"fullTitle": "index yourAnimal() does not hard-code the answer",
"duration": 1,
"currentRetry": 0,
"err": {}
},
{
"title": "returns a function",
"fullTitle": "index funkyFunction() returns a function",
"duration": 0,
"currentRetry": 0,
"err": {}
},
{
"title": "does not hard-code the answer",
"fullTitle": "index theFunk does not hard-code the answer",
"duration": 0,
"currentRetry": 0,
"err": {}
}
]
}
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Contributing to Learn.co Curriculum

We're really excited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible.

## Raising an Issue to Encourage a Contribution

If you notice a problem with the curriculum that you believe needs improvement
but you're unable to make the change yourself, you should raise a Github issue
containing a clear description of the problem. Include relevant snippets of
the content and/or screenshots if applicable. Curriculum owners regularly review
issue lists and your issue will be prioritized and addressed as appropriate.

## Submitting a Pull Request to Suggest an Improvement

If you see an opportunity for improvement and can make the change yourself go
ahead and use a typical git workflow to make it happen:

* Fork this curriculum repository
* Make the change on your fork, with descriptive commits in the standard format
* Open a Pull Request against this repo

A curriculum owner will review your change and approve or comment on it in due
course.

# Why Contribute?

Curriculum on Learn is publicly and freely available under Learn's
[Educational Content License](https://learn.co/content-license). By
embracing an open-source contribution model, our goal is for the curriculum
on Learn to become, in time, the best educational content the world has
ever seen.

We need help from the community of Learners to maintain and improve the
educational content. Everything from fixing typos, to correcting
out-dated information, to improving exposition, to adding better examples,
to fixing tests—all contributions to making the curriculum more effective are
welcome.
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Learn.co Educational Content License

Copyright (c) 2016 Flatiron School, Inc

The Flatiron School, Inc. owns this Educational Content. However, the Flatiron School supports the development and availability of educational materials in the public domain. Therefore, the Flatiron School grants Users of the Flatiron Educational Content set forth in this repository certain rights to reuse, build upon and share such Educational Content subject to the terms of the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). You must read carefully the terms and conditions contained in the Educational Content License as such terms govern access to and use of the Educational Content.

Flatiron School is willing to allow you access to and use of the Educational Content only on the condition that you accept all of the terms and conditions contained in the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). By accessing and/or using the Educational Content, you are agreeing to all of the terms and conditions contained in the Educational Content License. If you do not agree to any or all of the terms of the Educational Content License, you are prohibited from accessing, reviewing or using in any way the Educational Content.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
JavaScript Fix the Scope Lab
---

## Objectives

- Explore scope in JavaScript
- Exercise bug-finding skills related to scope issues

## Instructions

In this lab, you'll need to debug some issues related to function scope in JavaScript: variables might not be what we expect, certain variables might be unavailable, and in general havoc might be set loose in the current code.

As usual, start by running the specs and reading the results. Then fix some things, run the tests again, and repeat.

You're probably pretty good at this right now — good luck!

## Resources

- [MDN: Scope](https://developer.mozilla.org/en-US/docs/Glossary/Scope)
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var animal = 'dog'

function myAnimal() {
return animal
}

function yourAnimal() {
// How can we make sure that this function
// and the above function both pass?
// P.S.: You can't just hard-code 'cat' below
return animal
}

function add2(n) {
return n + two

// Feel free to move things around!
const two = 2
}

var funkyFunction = function() {
return function() {
return "FUNKY!"
}
}

// We want this to return "FUNKY!" -- how can we accomplish that?
var theFunk = funkyFunction()
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "javascript-fix-the-scope-lab",
"version": "0.1.0",
"description": "Practice with function scope in JavaScript on Learn.co",
"main": "index.js",
"scripts": {
"test": "mocha -R mocha-multi --reporter-options nyan=-,json=.results.json"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/learn-co-curriculum/javascript-fix-the-scope-lab.git"
},
"keywords": [
"javascript",
"flatiron",
"learn"
],
"author": "pletcher",
"license": "SEE LICENSE IN LICENSE.md",
"bugs": {
"url": "https://github.com/learn-co-curriculum/javascript-fix-the-scope-lab/issues"
},
"homepage": "https://github.com/learn-co-curriculum/javascript-fix-the-scope-lab#readme",
"devDependencies": {
"chai": "^3.5.0",
"jsdom": "^8.5.0",
"mocha": "^2.4.5",
"mocha-jsdom": "^1.1.0",
"mocha-multi": "^0.9.0"
}
}
53 changes: 53 additions & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*global describe, it */

const expect = require('chai').expect
const fs = require('fs')
const jsdom = require('mocha-jsdom')
const path = require('path')

const file = fs.readFileSync(path.resolve(__dirname, '..', 'index.js'), 'utf-8')

describe('index', () => {
jsdom({
src: file
})

describe('myAnimal()', () => {
it('returns my animal', () => {
expect(myAnimal()).to.equal('dog')
})
})

describe('yourAnimal()', () => {
it('returns your animal', () => {
expect(yourAnimal()).to.equal('cat')
})

it('does not hard-code the answer', () => {
expect(yourAnimal.toString()).not.to.contain("return 'cat'")
})
})

describe('add2(n)', () => {
it('adds two to n', () => {
const n = Math.floor(Math.random() * 1000)
expect(add2(n)).to.equal(n + 2)
})
})

describe('funkyFunction()', () => {
it('returns a function', () => {
expect(funkyFunction()).to.be.a('function')
})
})

describe('theFunk', () => {
it('is "FUNKY!"', () => {
expect(theFunk).to.equal('FUNKY!')
})

it('does not hard-code the answer', () => {
expect(file).to.contain('var theFunk = funkyFunction()')
})
})
})

0 comments on commit 941573b

Please sign in to comment.