Tabs after index

Tell us what’s happening:
Describe your issue in detail here.
i got a question for you guys. is tabsafterindex(index+1) make the value of the parameter index =2 , tabs.afterindex(2) or tabsafterindex(3) ?

   **Your code so far**

// tabs is an array of titles of each site open within the window
var 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

 var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
 var 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;

// Let's create three browser windows
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites

// Now perform the tab opening, closing, and other operations
var finalTabs = socialWindow
 .tabOpen() // Open a new tab for cat memes
 .join(videoWindow.tabClose(2)) // Close third tab in video window, and join
   **Your browser information:**

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

Challenge: Understand the Hazards of Using Imperative Code

Link to the challenge:

var tabsAfterIndex = this.tabs.slice(index + 1);

its this part where im confused . i thought this line of code should be this.tabs.splice(3)

tabsAfterIndex is part of the tabClose method and the parameter index is dynamic.

If you pass in 1 as the index to the method tabsAfterIndex would be 2.
If you pass in 2, then it would be 3.

i thought this line of code should be this.tabs.splice(3)

What is your reason behind this statement?

because index is a parameter thats passed as 2 and if u add one to it, it becomes 3. as in the second test it says “index+1”

i was referring to the hint that it bases on the initial test phase as a value of 2 to tabclose(). but it says on the hint when a 2 is passed tabsafterindex is tabs.splice2) not tabs.splice(3).

tabClose = function (index) {
 1. var tabsBeforeIndex = this.tabs.splice(0, index); // get the tabs before the tab
 2. var tabsAfterIndex = this.tabs.splice(index); // get the tabs after the tab

 3. this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // join them together 
 4. return this;

For an index, we will take 2 - as done in the challenge.

this elaborates what im getting at. its . one line 2, he defined tabsafterindex as this.tabs.splice(index) . he neglected that +1 that was added to it. if thats the cae then it makes since it was splice(2) and not splice(3) . and the execution even confirms it that way to.

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