1.7 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244c0 Global vs. Local Scope in Functions 1 功能中的全局与局部范围

Description

可以使本地变量和全局变量具有相同的名称。执行此操作时, local变量优先于global变量。在这个例子中:
var someVar =“帽子”;
function myFun{
var someVar =“Head”;
返回someVar;
}
函数myFun将返回"Head"因为存在变量的local版本。

Instructions

将一个局部变量添加到myOutfit函数,以使用"sweater"覆盖outerWear的值。

Tests

tests:
  - text: 不要更改全局<code>outerWear</code>的值
    testString: 'assert(outerWear === "T-Shirt", "Do not change the value of the global <code>outerWear</code>");'
  - text: <code>myOutfit</code>应该返回<code>&quot;sweater&quot;</code>
    testString: 'assert(myOutfit() === "sweater", "<code>myOutfit</code> should return <code>"sweater"</code>");'
  - text: 不要更改return语句
    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

// solution required