1.8 KiB
1.8 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
56533eb9ac21ba0edf2244c0 | Global vs. Local Scope in Functions | 1 |
Description
local
variable takes precedence over the global
variable.
In this example:
var someVar = "Hat";The function
function myFun() {
var someVar = "Head";
return someVar;
}
myFun
will return "Head"
because the local
version of the variable is present.
Instructions
myOutfit
function to override the value of outerWear
with "sweater"
.
Tests
- text: Do not change the value of the global <code>outerWear</code>
testString: 'assert(outerWear === "T-Shirt", ''Do not change the value of the global <code>outerWear</code>'');'
- text: <code>myOutfit</code> should return <code>"sweater"</code>
testString: 'assert(myOutfit() === "sweater", ''<code>myOutfit</code> should return <code>"sweater"</code>'');'
- text: Do not change the return statement
testString: 'assert(/return outerWear/.test(code), ''Do not change the return statement'');'
Challenge Seed
// Setup
var outerWear = "T-Shirt";
function myOutfit() {
// Only change code below this line
// Only change code above this line
return outerWear;
}
myOutfit();
Solution
var outerWear = "T-Shirt";
function myOutfit() {
var outerWear = "sweater";
return outerWear;
}