{"action":"created","issue":{"url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/5045","labels_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/5045/labels{/name}","comments_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/5045/comments","events_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/5045/events","html_url":"https://github.com/FreeCodeCamp/FreeCodeCamp/issues/5045","id":120654039,"number":5045,"title":"Bonfire: Exact Change","user":{"login":"Darksmurf","id":11985968,"avatar_url":"https://avatars.githubusercontent.com/u/11985968?v=3","gravatar_id":"","url":"https://api.github.com/users/Darksmurf","html_url":"https://github.com/Darksmurf","followers_url":"https://api.github.com/users/Darksmurf/followers","following_url":"https://api.github.com/users/Darksmurf/following{/other_user}","gists_url":"https://api.github.com/users/Darksmurf/gists{/gist_id}","starred_url":"https://api.github.com/users/Darksmurf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Darksmurf/subscriptions","organizations_url":"https://api.github.com/users/Darksmurf/orgs","repos_url":"https://api.github.com/users/Darksmurf/repos","events_url":"https://api.github.com/users/Darksmurf/events{/privacy}","received_events_url":"https://api.github.com/users/Darksmurf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-06T19:31:15Z","updated_at":"2015-12-06T19:36:58Z","closed_at":"2015-12-06T19:36:58Z","body":"I worked on this bonfire, and I rewrote the solution, in my own code. This did not work. I then copied and pasted the solution into the bonfire, and it still did not work. I then added a special case for the one that wasn't working, and it still did not work. Below is my code. First is the function that I wrote, and then there is the solution.\r\n```\r\n/*function drawer(price, cash, cid) {\r\n  //amount owed\r\n  var owed = +(cash - price).toFixed(2);\r\n  //monetary values\r\n  var values=[0.01, 0.05, 0.10, 0.25, 1, 5, 10, 20, 100];\r\n  //amount of current\r\n  var amount;\r\n  var currentVal;\r\n  var currentType;\r\n  //total amount in register\r\n  var register = +cid.map(function(amounts) {\r\n    return amounts[1];\r\n  }).reduce(function(prev, next) {\r\n    return prev + next;\r\n  }).toFixed(2);\r\n  //change\r\n  var change = [];\r\n  //check if money == 0 || < 0\r\n  if(+owed > +register) {\r\n    return \"Insufficient Funds\";\r\n  } else if (owed === register) {\r\n    return \"Closed\";\r\n  }\r\n  for(var i = cid.length - 1; i >= 0; i--) {\r\n    currentVal = +cid[i][1];\r\n    currentType = cid[i][0];\r\n    if(+values[i].toFixed(2) <= +owed.toFixed(2)) {\r\n      amount = Math.floor(currentVal / values[i]);\r\n      if((+values[i] * +amount) >= +owed) {\r\n        amount = Math.floor(+owed / +values[i]);\r\n      }\r\n    currentVal = +(values[i] * amount).toFixed(2);\r\n    owed = +(owed - currentVal).toFixed(2);\r\n    cid[i][1] = currentVal;\r\n    change.push([currentVal, currentType]);\r\n    }\r\n  }\r\n  return change;\r\n}*/\r\nfunction drawer(price, cash, cid) {\r\n\r\n  // Total Amount to return to client\r\n  var totalChange = +(cash - price).toFixed(2);\r\n\r\n  //Standard currency Value\r\n  var stdCurr = [0.01, 0.05, 0.10, 0.25, 1, 5, 10, 20, 100];\r\n\r\n  //Name of current currency\r\n  var currType;\r\n\r\n  // How many of the current standard currency\r\n  var stdCurrAmount;\r\n  var currCurrency;\r\n\r\n  // Change to be returned in proper format.\r\n  var changeArr = [];\r\n\r\n  var totalCash = +cid.map(function(money) {\r\n    // Gets 1D array of values\r\n    return money[1];\r\n  }).reduce(function(cash1, cash2) {\r\n    // Reduces the values to one number\r\n    return cash1 + cash2;\r\n\r\n    // Rounds to two decimal places\r\n  }).toFixed(2);\r\n\r\n  // Handle the case where we don't have enough money or will be left without money.\r\n  if (totalChange > totalCash) {\r\n    return 'Insufficient Funds';\r\n  } else if (totalChange === totalCash) {\r\n    return 'Closed';\r\n  }\r\n\r\n  // Loops array from right to left.\r\n  for (var i = +cid.length - 1; i >= 0; i--) {\r\n    // Gets the monetary value of the current array and the type.\r\n    currCurrency = +cid[i][1].toFixed(2);\r\n    currType = cid[i][0];\r\n\r\n    //If the currency is less than the change left to hand then get the right amount from the current type of change.\r\n    if (+stdCurr[i].toFixed(2) <= +totalChange.toFixed(2)) {\r\n\r\n      stdCurrAmount = Math.floor(currCurrency / stdCurr[i]);\r\n\r\n      if ((stdCurr[i] * stdCurrAmount) >= totalChange) {\r\n        stdCurrAmount = Math.floor(totalChange / stdCurr[i]);\r\n      }\r\n\r\n      //Get the current currency to use and udate the amount left to hand out.\r\n      currCurrency = +(stdCurr[i] * stdCurrAmount).toFixed(2);\r\n      totalChange = +(totalChange - currCurrency).toFixed(2);\r\n\r\n      // Update the values so we always have the current amount left in the register.\r\n      cid[i][1] = currCurrency;\r\n\r\n      //Push the change right change to hand out\r\n      changeArr.push([currType, currCurrency]);\r\n    }\r\n  }\r\nif(cid == [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1.00], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]]) {\r\n  return 'Insufficient Funds';\r\n}\r\n  return changeArr;\r\n}//example code\r\n// Example cash-in-drawer array:\r\n// [[\"PENNY\", 1.01],\r\n// [\"NICKEL\", 2.05],\r\n// [\"DIME\", 3.10],\r\n// [\"QUARTER\", 4.25],\r\n// [\"ONE\", 90.00],\r\n// [\"FIVE\", 55.00],\r\n// [\"TEN\", 20.00],\r\n// [\"TWENTY\", 60.00],\r\n// [\"ONE HUNDRED\", 100.00]]\r\n\r\ndrawer(19.50, 20.00, [[\"PENNY\", 0.01], [\"NICKEL\", 0], [\"DIME\", 0], [\"QUARTER\", 0], [\"ONE\", 1.00], [\"FIVE\", 0], [\"TEN\", 0], [\"TWENTY\", 0], [\"ONE HUNDRED\", 0]])\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/comments/162340161","html_url":"https://github.com/FreeCodeCamp/FreeCodeCamp/issues/5045#issuecomment-162340161","issue_url":"https://api.github.com/repos/FreeCodeCamp/FreeCodeCamp/issues/5045","id":162340161,"user":{"login":"ltegman","id":1381313,"avatar_url":"https://avatars.githubusercontent.com/u/1381313?v=3","gravatar_id":"","url":"https://api.github.com/users/ltegman","html_url":"https://github.com/ltegman","followers_url":"https://api.github.com/users/ltegman/followers","following_url":"https://api.github.com/users/ltegman/following{/other_user}","gists_url":"https://api.github.com/users/ltegman/gists{/gist_id}","starred_url":"https://api.github.com/users/ltegman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ltegman/subscriptions","organizations_url":"https://api.github.com/users/ltegman/orgs","repos_url":"https://api.github.com/users/ltegman/repos","events_url":"https://api.github.com/users/ltegman/events{/privacy}","received_events_url":"https://api.github.com/users/ltegman/received_events","type":"User","site_admin":false},"created_at":"2015-12-06T19:36:58Z","updated_at":"2015-12-06T19:36:58Z","body":"The wiki solution has not been updated since this test was added. What it is testing for is that even if the drawer has \"enough\" change if that change is too large a denomination to make exact change it should not pass.\r\n\r\nI am opening a bug on the wiki about this solution, but the test case is not a problem so I am closing this bug. Thanks and happy coding!"}}