Coin Change Calculator

I need to write function that calculates the coins you would use to give a customer their change in a shop. The function takes one argument, which is the amount of change needed, in pence. The function should always return an object. for example 13p change should be returned like this:

changeCalculator(13);
// should return {‘10’:1,‘2’:1,‘1’:1}

I’m stuck (new to coding), can someone direct me on ways to go about writing the function?

function changeCalculator (num) {

  var res = {};

  if (num < 0) return -1;
  if (num === 0) return 0;
  
  for (var i = 0; i < num.length; i++) {
      
  }
  return res;
};

Thank you,

We can’t write the code for you, but we can help you brainstorm and debug. What ideas have you had so far?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.