Stand in Line problem

Tell us what’s happening:
How are the argument being passed to the function’s parameter ?

Your code so far


function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  var remove = arr.shift();  // Change this line
  return remove;
}

// Test Setup

var testArr = [1,2,3,4,5];

// Display Code

console.log(nextInLine(testArr, 10, testArr[4])); // Modify this line to test

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/stand-in-line

It’s a function that takes an array and a value (any value, doesn’t matter what type). Those are the parameters. arr and item. So that’s two arguments you give to the function: an array and a value of some sort. Not three

I think the misunderstanding is that the Arguments is passed to Function rather than Parameters , Parameters is just one of the information of the Function object it belongs to, and if you pass some arguments to a function, they will be processed according to the Parameters information to become truncated or appended with the undefined, this behavior is handled by VM therefore it’s a runtime behavior.

Actually my doubt was with argument as i am passing three argument and there are only 2 parameters so the third argument that i have passed will just be ignored and the first two will be passed to the parameters

i meant when we are calling the function we are passing 3 argument but there are only 2 parameters so the third argument will just get ignored and the function will execute

correct me if i am wrong

the third argument is still passed on the function, in fact if you check what the arguments object contains, it is there (check it’s value!). it is not passed to a parameter as there is not a parameter available for that value tho

yeah correct

btw how to check those objects ?

try a console.log statetment so you see what’s inside it
you can access the arguments using bracket notation and numbers

arguments is an array-like object, you can get the first argument as arguments[0], the second as arguments[1] etc

1 Like

yeah i will look into that

You are exactly right - if the function signature identifies two parameters by name, then you will have exactly two variables with those names - in this case, you have arr as the first parameter (local variable), and item as the second.

Info on the keyword arguments can be found here. arguments is a keyword in javascript, within a function it contains an “Array-like” structure listing all parameters, whether assigned to a local variable or not. Handy way of allowing all sorts of parameters to be passed.

@ieahleen @snowmonkey @DanCouper @hsiaosiyuan0

guys i have one problem i am not able to get the challenges saved when i complete one challenge and jump to next then the previous one is not being saved although i am logged in and i am able to get the completed tick mark in the curriculum.

There are two different types of saved progress for Free Code Camp: your profile and your browser cache.

A list of your completed challenges is saved to your account in the FCC database. You can see the list of completed challenges by looking at your public portfolio. With a growing curriculum already over 1,400 lessons and a community of millions of people, FCC does not store every solution to every challenge in its database. When you complete a challenge, there is a modal that gives you the option to download your solution. This gives you the option to save a copy of any solution that you may want to reference later. There are some challenges which are classified as projects required for certifications. Your solutions to those can be viewed on your settings page.

Your in-editor code is saved in your browser’s local storage. Recent in-progress code from the challenge editor is also saved in your local browser cache when you run tests. If you are completing lessons and do not see your recent code, then your local storage has been cleared or something is preventing FCC from writing to your browser’s storage. This could be a browser setting, a privacy extension, or a browser version incompatibility. Especially as you get to more complicated challenges that may take multiple sessions, I strongly recommend saving your in-progress work outside of the browser cache.

This is a good opportunity to learn the ins and outs of your GitHub account, but you can also just save locally or use a service like repl.it which allows for versioning.

Only the challenges themselves, and not the interim lessons, are stored on th server. My suggestion? Download the lesson when you complete it. I actually wrote a FCC solution parser, because they’re in a funky JSON format. :wink:

download will give a json formatted file should i copy codes to text editor and keep record in my repo?

@snowmonkey

any solution to the prevention from being saved into the local storage
@ieahleen

that’s a browser setting, try googling local storage for your browser and see if you find how to make it stay
note that once you clean your browser cache it will be wiped once again

Simply save the downloaded files, create a directory for FCC, maybe one for each course track you’re working on, and store the JSON files there. I’ll see if I can find my codepen with an FCC JSON lesson reader I’d written last year.

EDIT: well that was easy - https://codepen.io/snowmonkey/full/Xyejpe

Just store your files locally, they’ll be in a JSON format, and keep a reference to that codepen. It’ll open the JSON file and pull out the index.js portion for display.

The other option, which I strongly recommend, is doing your development/testing on a different server entirely. You can see the calls that will be made for testing for each lesson, they’re in the pass/fail section. I will often copy the lesson code, and put it into a https://repl.it/ to experiment on and test out. Doing that, even when the lesson is completed and I’ve moved on, I have a working backup for each lesson.

yeah i will check that out now

that would be a big help if u can ig i need to let go of current challenges that i have although they were quite easy apart from some JS challenges which i can make again