Imperative Code

Can some help me to understand which one is the passed in (otherWindow) parameter.

Here is the code.

const Window = function(tabs) {
  this.tabs = tabs; 
};
Window.prototype.join = function(otherWindow) {
  this.tabs = this.tabs.concat(otherWindow.tabs);
  return this;
};
Window.prototype.tabOpen = function(tab) {
  this.tabs.push('new tab'); // Let's open a new tab for now
  return this;
};
Window.prototype.tabClose = function(index) {

  // Only change code below this line

  const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
  const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab

  this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together

  // Only change code above this line

  return this;
 };
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites

const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites

const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); 
const finalTabs = socialWindow
  .tabOpen() // Open a new tab for cat memes
  .join(videoWindow.tabClose(2)) // Close third tab in video window, and join
  .join(workWindow.tabClose(1).tabOpen());
console.log(finalTabs.tabs);

here the function is created

and then it is used here twice
so in the first case otherWindow takes the value of videoWindow.tabClose(2). and in the other of workWindow.tabClose(1).tabOpen()

Thank you so much Ilenia! I got it now.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.