Created
April 18, 2017 07:26
-
-
Save anonymous/b524ae6b7a69bb8f2829d49972bbb08c to your computer and use it in GitHub Desktop.
7.3 Scope Koans created by smillaraaq - https://repl.it/HHlS/5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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