Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.5 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244bf 局部作用域和函数 1 https://scrimba.com/c/cd62NhM 18227 local-scope-and-functions

--description--

在一个函数内声明的变量,以及该函数的参数都是局部变量,意味着它们只在该函数内可见。

这是在函数myTest内声明局部变量loc的例子:

function myTest() {
  var loc = "foo";
  console.log(loc);
}
myTest(); // logs "foo"
console.log(loc); // loc is not defined

在函数外,loc是未定义的。

--instructions--

在函数myFunction内部声明一个局部变量myVar,并删除外部的 console.log。

提示:
如果你遇到了问题,可以先尝试刷新页面。

--hints--

未找到全局的myVar变量。

assert(typeof myVar === 'undefined');

需要定义局部的myVar变量。

assert(/var\s+myVar/.test(code));

--seed--

--seed-contents--

function myLocalScope() {

  // Only change code below this line

  console.log('inside myLocalScope', myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log('outside myLocalScope', myVar);

--solutions--

function myLocalScope() {

  // Only change code below this line
  var myVar;
  console.log('inside myLocalScope', myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log('outside myLocalScope', myVar);