Randell Dawson e9212c61d2 fix(curriculum): Remove unnecessary assert message argument from English challenges JavaScript Algorithms and Data Structures - 01 (#36401)
* fix: rm assert msg basic-javascript

* fix: removed more assert msg args

* fix: fixed verbiage

Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com>
2019-07-13 08:07:53 +01:00

1.6 KiB

id, title, challengeType, videoUrl
id title challengeType videoUrl
56533eb9ac21ba0edf2244c0 Global vs. Local Scope in Functions 1 https://scrimba.com/c/c2QwKH2

Description

It is possible to have both local and global variables with the same name. When you do this, the local variable takes precedence over the global variable. In this example:
var someVar = "Hat";
function myFun() {
  var someVar = "Head";
  return someVar;
}

The function myFun will return "Head" because the local version of the variable is present.

Instructions

Add a local variable to myOutfit function to override the value of outerWear with "sweater".

Tests

tests:
  - text: Do not change the value of the global <code>outerWear</code>
    testString: assert(outerWear === "T-Shirt");
  - text: <code>myOutfit</code> should return <code>"sweater"</code>
    testString: assert(myOutfit() === "sweater");
  - text: Do not change the return statement
    testString: assert(/return outerWear/.test(code));

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;
}