declineEverything() and acceptEverything()

Hey coders!

I have one question, is it someone who can explain where the ‘e’ come from in the function at the bottom of this page? arr.forEach(e => …

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

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

// Checkpoint 1 solutions:
const declineEverything = arr => {
arr.forEach(politelyDecline)
}

/*
// As a function declaration:
function declineEverything(arr) {
arr.forEach(politelyDecline)
}
*/

// Checkpoint 2 solutions:
// Using an anonymous function and string interpolation:
const acceptEverything = arr => {
arr.forEach(e => {
console.log(Ok, I guess I will eat some ${e}.)
})
}

thanks for the help i can get.

Hello, and welcome to the forums

That’s the name of the parameter. You can make it whatever you’d like.

const acceptEverything = arr => {
  arr.forEach(e => {
    console.log(`Ok, I guess I will eat some ${e}.`)
  })
}

is the same as

const acceptEverything = arr => {
  arr.forEach(myParameter => {
    console.log(`Ok, I guess I will eat some ${myParameter}.`)
  })
}

same goes for the arr parameter. That can also be changed

const acceptEverything = arrayFood => {
  arrayFood.forEach(e => {
    console.log(`Ok, I guess I will eat some ${e}.`)
  })
}

Unless the exercise specifies what you should name the parameters, then you can name them whatever you’d like.

1 Like

Welcome to the forums!
just a small hint, there is a tool in Codecademy forums to refactor your code so it can be more readable, you can find it next to the upload tool or just use ctrl + shift + c as a shortcut. you can edit your post, select your code and use the tool.