Some of the parts of the code cannot be acessed

3889 views javascript
0

I though this was well made, but i am using quokka for vscode and it appears to be that is malfunctioning.

const getCash = (credit, saved) => {
  let returnedCash = []
  for (const obj of saved) {
    for (let i = 0; i < obj.amount; i++) {
      if (credit > 0) {
        if (credit - obj.value < 0) break
        credit -= obj.value
        returnedCash = [...returnedCash, {
          value: obj.value,
          amount: 1
        }]
      }
    }
  }
  return (credit > 0) ? 'No hay suficiente dinero. Lo sentimos.' : returnedCash
}

const saved1 = [{
    value: 50,
    amount: 5
  },
  {
    value: 20,
    amount: 10
  },
  {
    value: 10,
    amount: 35
  },
  {
    value: 1,
    amount: 100
  }
]

const res = getCash(200, saved1)
console.log(res);

It happens in line 6, with a yellow mark.

answered question

Welcome to Stack Overflow! Please take the tour (you get a badge!), have a look around, and read through the help center, in particular How do I ask a good question? What is the code supposed to do? What is it doing instead? What error does the tool give you to go with the yellow mark? Which line is line 6 (yes, we can count, but we can't be sure you don't have blank lines that didn't get copied, etc.).

Yep! Sure appears that is malfunctioning. Is there a question, goal, challenge, issue? Or are you just letting us know?

1 Answer

11

And so do in line 12. I would really appreciate it :)

posted this

Have an answer?

JD

Please login first before posting an answer.