Global vs Local Scope in Functions_contradictory instructions

Global vs Local Scope in Functions_contradictory instructions
0

#1

Tell us what’s happening:
Hi! I think the challenges instructions are contradictory ones:
“Instructions: Add a local variable to myOutfit to override the value of outerWear with “sweater”.”

but

in the error console tell me this: “Do not change the value of the global outerWear”

so, I don’t realise how can I override the value of outeWear and don’t change its value at the same time. =(

Your code so far

var outerWear = "T-Shirt";

function myOutfit() {
  // Only change code below this line
  var myOutfit = "sweater";
  outerWear = myOutfit;
  
  // Only change code above this line
  return outerWear;
}

myOutfit();

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0.

Link to the challenge:


#2

The myOutfit in myOutfit should return "sweater" refers to the function myOutfit().
This exercise is showing scoping.

Answer
// Setup
var outerWear = "T-Shirt";

function myOutfit() {
  // Only change code below this line
  
  var outerWear = 'sweater';
  
  // Only change code above this line
  return outerWear;
}

myOutfit();

#3

alright here’s the condition

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

Do not change the value of the global outerWear

myOutfit should return “sweater”

Do not change the return statement

Answer:

// Setup
var outerWear = “T-Shirt”;

function myOutfit() {
// Only change code below this line

var myOutfit = “sweater”;
outerWear= myOutfit;// saticfying all condintions and just swap the value

// Only change code above this line
return outerWear;
}

myOutfit;