Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

javascripting

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

javascripting - npm Package Compare versions

Comparing version 1.12.0 to 2.0.0

i18n/es.json

8

index.js
#!/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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc