FAQ: Code Challenges: Intermediate JavaScript - declineEverything() and acceptEverything()

Excuse me for the bother, but can you please explain to me where in the exercise does it say that for the second point, we need to create a variable called ‘grudginglyAccept’ to include that console log message? Why can’t we just include it in the same function ‘acceptEverything’ as follows:

const acceptEverything = arr2 => {

  let i = 0;

  arr2.forEach(console.log(`Ok, I guess I will eat some ${arr2}.`));

}

console.log(acceptEverything(veggies));

I think what is wrong there is that you were supposed to call ‘arr’ instead of ‘veggies’, because you are using the parameter as a reference for the veggies array to be taken into the function. Hope this helps.

1 Like

Good Day All! I “passed” this exercise however, my code returns the appropriate denial and acceptance statements for each of the four veggies as well as “undefined” like so:
No broccoli please. I will have pizza with extra cheese.
No spinach please. I will have pizza with extra cheese.
No cauliflower please. I will have pizza with extra cheese.
No broccoflower please. I will have pizza with extra cheese.
undefined
Ok, I guess I will eat some broccoli.
Ok, I guess I will eat some spinach.
Ok, I guess I will eat some cauliflower.
Ok, I guess I will eat some broccoflower.
undefined

Any ideas why that is happening?

const veggies = [‘broccoli’, ‘spinach’, ‘cauliflower’, ‘broccoflower’];

const politelyDecline = (veg) => {
console.log(‘No ’ + veg + ’ please. I will have pizza with extra cheese.’);}

const declineEverything = (array) => {console.log((array).forEach(politelyDecline));}

declineEverything(veggies);

const grudginglyAccept = (veg) => {
console.log("Ok, I guess I will eat some " + veg + “.”);}

const acceptEverything = (array) => {console.log((array).forEach(grudginglyAccept));}

acceptEverything(veggies);

Do the instructions ask us to log inside the function, or to return and log at the caller?

I see that it did ask me to make the console.log within the grudginglyAceept and politleyDecline functions. When I removed the console.log from the acceptEverything and declineEverything functions, it worked properly and did not add the extra “undefined” at the end. In fooling around I see that once console.log is removed from both grudginglyAccept and acceptEverything neither of these produce errors but of course, nothing prints:

acceptEverything(veggies);
veggies.forEach(grudginglyAccept);

However, both will say undefined if I try to console.log those statements directly like so:

console.log(acceptEverything(veggies));
console.log(veggies.forEach(grudginglyAccept));

If I include a console.log within acceptEverything, I get undefined as well, but putting the console.log within grudinglyAccept produces the right effect for both calls. So I see what it wanted me to do, but I am left not knowing precisely why the .forEach method doesn’t like to be logged…

We cannot log .forEach() because it has no return value. In this case you would be logging in the callback function, not at the caller.

1 Like

Hi all. I “passed” this exercise but my output is a little funky. The declineEverything array is not returning as it should. Gist and output below:

Gist: Codecademy export · GitHub

Output:

No broccoli,spinach,cauliflower,broccoflower please. I will have pizza with extra cheese.
Ok, I guess I will eat some broccoli.
Ok, I guess I will eat some spinach.
Ok, I guess I will eat some cauliflower.
Ok, I guess I will eat some broccoflower.

Maybe it was something messed up behind the scenes but I reset the question and copy + paste my code and we’re good now.

I’m not able to make any progression on this exercise. No matter the solution I type for task 1, for the declineEverything function, the box will not tick. So I can’t move to task 2.

I tried:
const declineEverything = (arr) => {
arr.forEach(politelyDecline)
}

Also tried various other ways to type it. AND even gave up and replaced my code with the solution and reset the exercise multiple times. NOTHING works.

Is anyone else having these issues? Has anyone found a solution?

The Ruby paths were full of problems like this and lots of people reported getting stuck in the forums. I’ve been loving this JS path until now :frowning:

SOLUTION: It seems that if you log out of Codecademy and log back in it might be the way to fix this problem. It worked now when I tried.