Global vs. Local Scope in Functions "I tried" but need Help[

Global vs. Local Scope in Functions "I tried" but need Help[
0

#1

Tell us what’s happening:

This is what I got so far…

Your code so far


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

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

myOutfit();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36 OPR/54.0.2952.54.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/global-vs--local-scope-in-functions


#2

You don’t need to declare a variable called myOutfit. The instruction just says add a local variable to myOutfit function. Follow the given example, re-delcare outerWear variable with value of sweater


#3

the wording is a bit confusing. You need to override outerWear so change

var myOutfit

to

var outerWear


#4

I tried it but it don’t work


#5

You need to post your current code for us to see what you tried.


#6

\same as above but it changed it to Outfit = “sweater” it says Outfit is not a function


#7

That is not what we told you to do. you need to use the outerWear variable.


#8

I removed the t shirt and placed sweater at the top it comes back right but it says not to change the value of global outerware


#9
// Setup
var outerWear = "T-Shirt";

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

myOutfit();

Do not change the code at the top.

Replace var myOutfit with var outerWear

You must set the variable twice.


#10

The instructions could be reworded as the following. See if this helps you solve the challenge.

Declare a local variable inside the myOutfit function and name it outerWear. Then, assign it the string value of “sweater”. When you assign “sweater” to the local variable outerWear, it will allow the myOutfit function to return “sweater” instead of the global variable’s value of “T-Shirt” with the added benefit of not changing the global variable’s value at all.


#11

I have don:
var myOutfit = “sweater”
var outerWare = " sweater"
myOutfit = “sweater”
outerWare = “sweater”
changer the t shirt
changed the last myOutfit & tried adding sweater to it which it said not to do
sweater by itself


#12

See my last reply for additional help and guidance.


#13

You did this inside the function?


#14

yes it comes back as Outfit should return as sweater


#15

I GOT IT “MISSPELLING” SORRY I NEED TO GO TO SLEEP
Thank you all for the help…