Stand in line, even the video guy sounds confused

Tell us what’s happening:
I think I am done with this. Even when I get the answer, I don’t understand why or what its for. It’s a journey into a void.

Your code so far


function nextInLine(arr, item) {
// Only change code below this line

return item;
// Only change code above this line


}

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

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));

Your browser information:

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

Challenge: Stand in Line

Link to the challenge:

Could you please elaborate on what exactly you find confusing?

Its says:
Write a function nextInLine which takes an array ( arr ) and a number ( item ) as arguments.
But that’s already there. Are we supposed to write it again or just move onto the next “instruction”.
For the next one I write:
arr.push(6);//to add 6 to the array, it shows up below - good

arr.shift();//to remove the first item from array, that also shows up below even better.
Then I run the tests and it comes up with errors:

nextInLine([2], 1)```should return```2``````nextInLine([5,6,7,8,9], 1)```should return```
5```After```nextInLine(testArr, 10)```,```testArr[4]```should be```10```

This is gibberish, where did 2 come from?

The function is supposed to return the item that is removed, i.e. the first item in the array. nextInLine([2], 1) should return 2 because 2 is the item that is going to be removed after you push 1 into it since 2 is the first item in the array.

You have to “complete” the function because the function is in skeletal shape (all modules have this type) and you have to complete it to make it do what it’s supposed to do.

If you’re still confused feel free to ask.

Tests put values into your function and run it: they test your function to see if it works. So the first test puts [2] and 1 in as arguments and expects 2 as a return value. Second one puts [5,6,7,8,9] and 1 in as arguments and expects 5 and so on

So you have a function set up what takes two arguments, and you fill in the body of it so it fits what it’s asking you to do. Then when you press the submit button, the tests run, putting values into your function to see if what comes out the other end is what they expect.

1 Like

Thanks but when you are confused it hard to put a question together. I will take a break. I have put a lot of time into this. I’m not stupid but I feel stupid with this. Not your fault, I know. Thanks anyway.

1 Like

I just want to thank you for replying. And I guess I will go back to it tomorrow. You know I understand the push and shift an unshift code, but these exercises just leave me scratching my head, it’s like I am reading a foreign language.

1 Like

I am working on this again and looking at your explanation. What is this idea of tests? The only place they mention test is on the button when you are finished. You talk about it as if that’s been explained.
Okay so you are explaining the bottom bit. But those test results don’t help me figure out what they want. This becomes a guessing game, not learning.

1 Like

Hi @martin21

You are not alone thinking this is confusing. I’m a little bit ahead of you in the challenges, and I’m almost always confused when I first begin a new challenge. A programming language is much different than learning CSS/HTML.

I’m continuing to go through the lessons, but I’m supplementing with other things I find so I get more practice, and hopefully understand a little more. I’ve gone back and done some of the challenges over again. I’ve started to write down or talk through the problem out loud. Say it in English first, then try to translate it into JavaScript. It’s a foreign language after all.

Also, sometimes copying and pasting your code into your browser console can be a good way to test what your code does. That is what they are doing when you hit the Run Test button.

Anyway, just wanted to say that you and I will understand it if we stick with it. We just have to muddle through, practice, and study.

2 Likes

Thanks Cheryl, yes I am sure you are right. Sometimes it just feels so deliberate. These are tiny steps, introducing a few lines of code at a time, you would think each time you would go, Oh yeah, that makes sense; right, move on. But I get half way through and suddenly, no that’s wrong, do it again, Why what - I did what you said, Or I have no idea what they are saying to do and the video does something completely unexpected.
I will calm down come back the next day and try again. Yes we will get there, whatever there is.

2 Likes

Hi Martin21,

I hear you. Sometimes I feel like I hit the wall and nothing else is getting in no matter what. But you will get it, it just takes a bit for it to come together.
Sometimes when I am really struggling I take a break for a few days and do something else that is related.

I have also been slowing down and taking more breaks while I am working and it seems to help. Because when you do get something it is so very satisfying! I think it is getting more enjoyable too, that is until I hit the next wall.
Stick with it, you can do it.

3 Likes

So test as in it’s testing that your code works. This is how FCC works – every challenge you’ve done tests your code to see if it passes.

This challenge is asking you to write a function, so the test for this on is checking that if you give the functions some values, the expected value is returned. You should be doing what the test is doing anyway – if you give it some array and some value, what is the result? If you give it a different array and a different value, what is the result?

If you think that this makes it a guessing, that suggests there’s something wrong with your code and/or that you don’t understand something fundamental. This is fine! It’s hard, getting stuck is always going to happen, that’s what this forum is here to help with.

I have my doubts about that. I think I know the fundamentals, it the language of the exercises that throws me. I hear they are upgrading the curriculum, for that I have hopes. Still I will preserver, with help from the forum people like yourself, there is a chance.

I don’t think a new curriculum is going to help here – I think there is possibly a basic fundamental misunderstanding of how to write a function here. Instead of banging your head against a wall, it’s a good idea to post the code that’s failing and that your stuck on, there are a lot of people here who can help

You might have noticed I am asking lots of questions. Yes there is a lack of understand the code syntax of the questions. I have come from khan which I think would be simpler but I have worked through this course from the beginning. I don’t know where else I should have expected to learn the local language.

I’m just suggesting that if you post the code you’re stuck on (as you have in other threads), people can help to try to explain where you are going wrong.

Yes, I am learning how this site works.

For those of you feeling frustrated. I have been working in this industry for over 15 years and I still find most of the coding “exercises” confusing.

The good news is that in my experience once you get a job in the industry, the actual problems you will be trying to solve are nothing like these exercises. I can’t think of a single puzzle solving exercise I have come across on any site where I was like “oh I wish I knew that when I was trying to solve …”. Concepts like design patterns are much more useful than any knowledge of how to solve puzzle problems.

Furthermore, most of this low level algorithmic logic has been encapsulated in languages and frameworks decades ago. The actual important thing is that you are becoming familiar with the syntax of a given language and concepts of programming in general.

So just think of these problem solving exercises as analogous to grade school math where they make you work out the problem without a calculator. Then when you get to the university level, we realize how silly that is and you get to use a calculator, because there is a reason the calculator was invented.

1 Like

Yes Jeremy, I totally believe that. I am really just looking for some interesting challenges. Expected to find something new here, a step up form Khan but I am actually repeating a lot of stuff. The language in the exercises is confusing and it like you have to get it right before you can move on. It’s just frustrating. Anyway the forum exchanges work it out.
The engagement is more interesting than the code which I will never use outside this site. I have spent about 18 months answering help requests at Khan; maybe I will do it here one day.

Yeah I found a lot of the challenges frustrating. You can actually help make them better https://contribute.freecodecamp.org/#/ I have found the people here very open to feed back and they do seem to have a genuine desire to make the site better. I have the site running locally on my machine and if I get some free time hope to contribute. For now I am just trying to give back a little by answering forum posts. You also have to remember the people making this site are all volunteers probably doing this in their spare time.

2 Likes