Skip to content

Instantly share code, notes, and snippets.

@AliceWonderland
Forked from anonymous/7.3 Scope Koans.js
Created April 18, 2017 07:26
Show Gist options
  • Save AliceWonderland/e848fcbbe0469230d74c89975a4aa1af to your computer and use it in GitHub Desktop.
Save AliceWonderland/e848fcbbe0469230d74c89975a4aa1af to your computer and use it in GitHub Desktop.
7.3 Scope Koans created by smillaraaq - https://repl.it/HHlS/5
var testOneMessage = "test failing";
function testOne(testOneMessage) {//every param becomes a new var local
// Test One Restrictions: Do not declare any new variable with the var keyword
// Do not reassign testOneMessage
console.log("Test one: ", testOneMessage);
}
// Run test one
testOne("test succeeding");
var testTwoMessage = "test failing"; //could have just changed this message
function testTwo() {
// Test Two Restrictions: Do not change any code in the body of this function
helperFunc();
console.log("Test two: ", testTwoMessage)
}
function helperFunc(a) {
testTwoMessage = "test succeeding";
return testTwoMessage; //does not need this line because i changed the global var value
}
// Run test two
testTwo()
console.log("Test Two: " + testTwoMessage);
var testThreeMessage = "test failing";
function testThree(testThreeMessage) {
// Test Three Restrictions: Do not change any code in the body of this funciton
// Type only a single character
if (testThreeMessage) {
testThreeMessage = "test succeeding";
}
function logMessage() {
console.log("Test three: ", testThreeMessage || "test failing");
}
logMessage();
}
// Run test test three
testThree(1)
var testFourMessage = "test succeeding";
function testFour(msg) {
// Test Four Restrictions: Delete only a single character anywhere in the body of this function
// Do not make any other changes
function innerFunc(msg) {
msg = msg
function doubleInner(msg) {
testFourMessag = msg;
return testFourMessage;
}
testFourMessage = doubleInner("test failing")
}
innerFunc(testFourMessage);
msg = testFourMessage;
console.log("Test four: ", testFourMessage)
}
// Run test four
testFour("test failing")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment