Functional Programming - Understand the Hazards of Using Imperative Code

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

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
// tabs is an array of titles of each site open within the window
const Window = function(tabs) {
  this.tabs = tabs; // We keep a record of the array inside the object
};

// When you join two windows into one window
Window.prototype.join = function(otherWindow) {
  this.tabs = this.tabs.concat(otherWindow.tabs);
  return this;
};

// When you open a new tab at the end
Window.prototype.tabOpen = function(tab) {
  this.tabs.push('new tab'); // Let's open a new tab for now
  return this;
};

// When you close a tab
Window.prototype.tabClose = function(index) {

  // Only change code below this line


this.tabs.plice(index.1)
// Let's create three browser windows
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']); // Entertainment sites

// Now perform the tab opening, closing, and other operations
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);

const browser1 = ['FB','Twiter','Youtube'];
const index = 0;
browser1.splice(index.1);
console.log(browser1)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62

Challenge: Functional Programming - Understand the Hazards of Using Imperative Code

Link to the challenge:

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

1 Like

At a glance:

this.tabs.plice(index.1)

and:

browser1.splice(index.1)

I’m surprised your text editor didn’t catch those. But thay may not be the whole story, depending on the issue.

1 Like

Side note - you’ve been asked to fill this in three times in a row. It really, honestly, actually helps us answer your question if you talk to us. Also, it is an important skill to practice.

1 Like

It is, but there are errors that need to be fixed before it can even get to that error.

@Ridhohaki The only code you need to change is the code inside the tabClose method. Look at the docs for splice it gives a hit as to what method to use instead.

1 Like