"Learn to code with free online courses, programming projects, and interview preparation for developer jobs...."
*
let butterbeer = () => "Butterbeer";let getBB = (numGlasses) => { let glassesOfBB = <>; for (let glassOfBB = 1; glassOfBB
*

Prepare 27 cups of green tea and 13 cups of black tea and store them in tea4GreenTeamFCCand tea4BlackTeamFCCvariables, respectively. Note that the getTeafunction has been modified so it now takes a function as the first argument.

You are watching: Functional programming: refactor global variables out of functions

Note: The data (the number of cups of tea) is supplied as the last argument.

/** * A long process to prepare green tea. *
return string A cup of green tea. **/const prepareGreenTea = () => "greenTea";/** * A long process to prepare black tea. *
return string A cup of black tea. **/const prepareBlackTea = () => "blackTea";/** * Get given number of cups of tea. *
param function():string prepareTea The type of tea preparing function. *
param number numOfCups Number of required cups of tea. *
return Array Given amount of tea cups. **/const getTea = (prepareTea, numOfCups) => { const teaCups = <>; for(let cups = 1; cups Answer:

const prepareGreenTea = () => "greenTea";//this is an arrow function//has no parameter; empty parenthesis ()//simply returns the string greenTeaconst prepareBlackTea = () => "blackTea";//same as above//but this one is for black tea instead of green tea//this is an arrow function that takes in two parameters//the first (prepareTea) takes in a function//this one depends on the type of tea you want//in this case, it can take in either the green or black tea functions//the second parameter is numOfCups//this one refers to the number of cups of teaconst getTea = (prepareTea, numOfCups) => { const teaCups = <>; //declare a new variable called teaCups //the initial value of this variable is an empty array //for loop //the initial value of the cups variable is 1 //the for loop will run as long as the valu of the cups variable is less than or equal to the given value of the numOfCups parameter //every time the for loop runs, increment cups by 1 (cups += 1 or cups = cups + 1) for(let cups = 1; cups

*

Understand the Hazards of Using Imperative Code

*
// tabs is an array of titles of each site open within the windowvar Window = function(tabs) this.tabs = tabs; // we keep a record of the array inside the object;// When you join two windows into one windowWindow.prototype.join = function (otherWindow) this.tabs = this.tabs.concat(otherWindow.tabs); return this;;// When you open a new tab at the endWindow.prototype.tabOpen = function (tab) this.tabs.push("new tab"); // let"s open a new tab for now return this;;// When you close a tabWindow.prototype.tabClose = function (index) var tabsBeforeIndex = this.tabs.splice(0, index); // get the tabs before the tab var tabsAfterIndex = this.tabs.splice(index); // get the tabs after the tab this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together return this; ;// Let"s create three browser windowsvar workWindow = new Window(<"GMail", "Inbox", "Work mail", "Docs", "freeCodeCamp">); // Your mailbox, drive, and other work sitesvar socialWindow = new Window(<"FB", "Gitter", "Reddit", "Twitter", "Medium">); // Social sitesvar videoWindow = new Window(<"Netflix", "YouTube", "Vimeo", "Vine">); // Entertainment sites// Now perform the tab opening, closing, and other operationsvar finalTabs = socialWindow .tabOpen() // Open a new tab for cat mim .join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(workWindow.tabClose(1).tabOpen());alert(finalTabs.tabs);When the code above is run, this alert shows up:

*

Fill in the code for the function incrementerso it returns the value of the global variable fixedValueincreased by one.

function incrementershould not change the value of fixedValue

incrementerfunction should return a value that is one larger than the fixedValuevalue.

See more: What Is A Result Of Connecting Two Or More Switches Together?

// the global variablevar fixedValue = 4;function incrementer () let newVal = fixedValue + 1; return newVal;var newValue = incrementer(); // Should equal 5console.log(fixedValue); // Should print 4console.log(newValue); //returns 5or:

// the global variablevar fixedValue = 4;var incrementer = () => fixedValue + 1;var newValue = incrementer();console.log(newValue);//returns 5console.log(fixedValue);//returns 4

Pass Arguments to Avoid External Dependence in a Function

*

The watchListarray holds objects with information on several movies. Use mapto pull the title and rating from watchListand save the new array in the ratingvariable. The code in the editor currently uses a forloop to do this, replace the loop functionality with your mapexpression.