javascripting
Advanced tools
Comparing version 1.12.0 to 2.0.0
#!/usr/bin/env node | ||
var path = require('path'); | ||
var adventure = require('adventure'); | ||
var jsing = adventure('javascripting'); | ||
var adventure = require('workshopper-adventure/adventure'); | ||
var jsing = adventure({ | ||
name: 'javascripting' | ||
, appDir: __dirname | ||
, languages: ['en', 'ja', 'ko', 'es', 'zh-cn'] | ||
}); | ||
@@ -7,0 +11,0 @@ var problems = require('./menu.json'); |
@@ -19,3 +19,4 @@ [ | ||
"FUNCTIONS", | ||
"FUNCTION ARGUMENTS" | ||
"FUNCTION ARGUMENTS", | ||
"SCOPE" | ||
] |
{ | ||
"name": "javascripting", | ||
"description": "Learn JavaScript by adventuring around in the terminal.", | ||
"version": "1.12.0", | ||
"version": "2.0.0", | ||
"repository": { | ||
@@ -14,8 +14,8 @@ "url": "git://github.com/sethvincent/javascripting.git" | ||
"dependencies": { | ||
"adventure": "^2.8.0", | ||
"cli-md": "^0.1.0", | ||
"colors": "^1.0.3", | ||
"diff": "^1.2.1" | ||
"diff": "^1.2.1", | ||
"workshopper-adventure": "^3.0.2" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -40,3 +40,3 @@ --- | ||
In that file, define array `food` : | ||
```js | ||
```js | ||
var food = ['apple', 'pizza', 'pear']; | ||
@@ -43,0 +43,0 @@ ``` |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -5,3 +5,3 @@ --- | ||
There are many ways to manipulate arrays. | ||
There are many ways to manipulate arrays. | ||
@@ -8,0 +8,0 @@ One common task is filtering arrays to only contain certain values. |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
--- | ||
# | ||
# SCOPE | ||
--- | ||
`Scope` is the set of variables, objects, and functions you have access to. | ||
JavaScript has two scopes: `global` and `local`. A variable that is declared outside a function definition is a `global` variable, and its value is accessible and modifiable throughout your program. A variable that is declared inside a function definition is `local`. It is created and destroyed every time the function is executed, and it cannot be accessed by any code outside the function. | ||
Functions defined inside other functions, known as nested functions, have access to their parent function's scope. | ||
Pay attention to the comments in the code below: | ||
```js | ||
var a = 4; // a is a global variable, it can be accesed by the functions below | ||
function foo() { | ||
var b = a * 3; // b cannot be accesed outside foo function, but can be accesed by functions | ||
// defined inside foo | ||
function bar(c) { | ||
var b = 2; // another `b` variable is created inside bar function scope | ||
// the changes to this new `b` variable don't affect the old `b` variable | ||
console.log( a, b, c ); | ||
} | ||
bar(b * 4); | ||
} | ||
foo(); // 4, 2, 48 | ||
``` | ||
IIFE, Immediately Invoked Function Expression, is a common pattern for creating local scopes | ||
example: | ||
```js | ||
(function(){ // the function expression is surrounded by parenthesis | ||
// variables defined here | ||
// can't be accesed outside | ||
})(); // the function is immediately invoked | ||
``` | ||
## The challenge: | ||
Create a file named `scope.js`. | ||
In that file, copy the following code: | ||
```js | ||
var a = 1, b = 2, c = 3; | ||
(function firstFunction(){ | ||
var b = 5, c = 6; | ||
(function secondFunction(){ | ||
var b = 8; | ||
(function thirdFunction(){ | ||
var a = 7, c = 9; | ||
(function fourthFunction(){ | ||
var a = 1, c = 8; | ||
})(); | ||
})(); | ||
})(); | ||
})(); | ||
``` | ||
Use your knowledge of the variables' `scope` and place the following code inside on of the functions in 'scope.js' | ||
so the output is `a: 1, b: 8,c: 6` | ||
```js | ||
console.log("a: "+a+", b: "+b+",c: "+c); | ||
``` | ||
--- |
--- | ||
# | ||
#EXCELLENT! | ||
You got it! The second function has the scope we were looking for. | ||
Run javascripting in the console to choose the next challenge. | ||
--- |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
@@ -1,44 +0,1 @@ | ||
var path = require('path'); | ||
var getFile = require('../../get-file'); | ||
var compare = require('../../compare-solution'); | ||
var problemName = __dirname.split(path.sep); | ||
problemName = problemName[problemName.length-1]; | ||
exports.problem = getFile(path.join(__dirname, 'problem.md')); | ||
exports.solution = getFile(path.join(__dirname, 'solution.md')); | ||
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js"); | ||
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md"); | ||
exports.verify = function (args, cb) { | ||
var attemptPath = path.resolve(process.cwd(), args[0]); | ||
compare(solutionPath, attemptPath, function(match, obj) { | ||
if(match) { | ||
return cb(true); | ||
} | ||
if(!obj) { | ||
// An error occured, we've already printed an error | ||
return; | ||
} | ||
var message = getFile(troubleshootingPath); | ||
message = message.replace(/%solution%/g, obj.solution); | ||
message = message.replace(/%attempt%/g, obj.attempt); | ||
message = message.replace(/%diff%/g, obj.diff); | ||
message = message.replace(/%filename%/g, args[0]); | ||
exports.fail = message; | ||
cb(false); | ||
}); | ||
}; | ||
exports.run = function (args) { | ||
require(path.resolve(process.cwd(), args[0])); | ||
}; | ||
module.exports = require("../../lib/problem")(__dirname) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
982633
285
6
283
2
+ Addedworkshopper-adventure@^3.0.2
+ Addedabbrev@1.1.1(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@1.0.02.2.1(transitive)
+ Addedcardinal@0.5.0(transitive)
+ Addedchalk@0.4.01.1.3(transitive)
+ Addedcharm_inheritance-fix@1.0.1(transitive)
+ Addedcolors@0.6.2(transitive)
+ Addedcolors-tmpl@0.1.1(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedesprima-fb@12001.1.0-dev-harmony-fb(transitive)
+ Addedextended-terminal-menu@2.1.4(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedi18n-core@1.3.3(transitive)
+ Addedmap-async@0.1.1(transitive)
+ Addedmkdirp@0.3.5(transitive)
+ Addedmsee@0.1.2(transitive)
+ Addedmustache@0.8.2(transitive)
+ Addednopt@2.1.2(transitive)
+ Addedobject-keys@0.4.0(transitive)
+ Addedredeyed@0.5.0(transitive)
+ Addedsimple-terminal-menu@1.1.3(transitive)
+ Addedsprintf@0.1.5(transitive)
+ Addedstrip-ansi@0.1.13.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedvarsize-string@2.2.2(transitive)
+ Addedwcsize@1.0.0(transitive)
+ Addedwcstring@2.1.1(transitive)
+ Addedworkshopper-adventure@3.5.2(transitive)
+ Addedxtend@2.1.2(transitive)
- Removedadventure@^2.8.0
- Removedadventure@2.11.1(transitive)
- Removedminimist@0.2.4(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedsplit@0.3.3(transitive)
- Removedthrough2@0.5.1(transitive)
- Removedx256@0.0.2(transitive)