Better Grasp of Understanding
AngelaThomas2 (3)

I have been meeting some difficulty with the lines of code on this repl:

https://repl.it/@AngelaThomas2/allCandyOrders .

When I run the code, it says I am passing half of what is expected, but failing on returning {} when called with []. Why might I be getting this error and how can I solve it out? I have gone back through this scenario and its entirety and can't find the missing piece of this puzzle.

You are viewing a single comment. View All
malvoliothegood (709)

@AngelaThomas2 let and const are recent additions to the JS language. It is better to use them instead of var because they give better protection to your code. Basically I always use const unless the value of a variable is likely to change, then I use let.

const animals = ['horse', 'pig', 'cow'];
// let is used to declare i as the value of i changes
for (let i = 0; i < animals.length; i++) {
  console.log('Hello ' + animals[i]);
}

Read more about var, let and const in this article: https://tylermcginnis.com/var-let-const/

I will look at your code again later today. I am guessing you were given boilerplate code to use by your teacher.