diff --git a/src/comment from make_change.js b/src/comment from make_change.js new file mode 100644 index 0000000..d3a5028 --- /dev/null +++ b/src/comment from make_change.js @@ -0,0 +1,87 @@ +/*const useQaurter = function(amountGiven, price) { + amountGiven = amountGiven - 25 + coins.qaurters++ + return amountGiven + + //console.log(amountGiven) + } + + + + + const useDime = function(amountGiven, price) { + amountGiven = amountGiven - 10 + coins.dimes++ + return amountGiven + + //console.log(amountGiven) + } + + + + const useNickel = function(amountGiven, price) { + amountGiven = amountGiven - 5 + coins.nickels++ + return amountGiven + + //console.log(amountGiven) + } + + + + const usePenny = function(amountGiven, price) { + amountGiven = amountGiven - 1 + coins.pennies++ + return amountGiven + + //console.log(amountGiven) + } + + function makeChange({price, amountGiven}) { + let results = {} + if(price === amountGiven) { + + results.quarters = coins.quarters + results.dimes = coins.dimes + results.nickels = coins.nickels + results.pennies = coins.pennies + + coins.quarters = 0 + coins.dimes = 0 + coins.nickels = 0 + coins.pennies = 0 + + + } + + if( difference >= 25 ) { + amountGiven = takeQuarter(amountGiven, coins) + return makeChange({price: price, amountGiven: amountGiven}) + }else if( difference >= 10) { + amountGiven = takeDime(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(difference >= 5){ + amountGiven = takeNickel(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(difference >= 1){ + amountGiven = takePenny(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + } + } +this worked + +function makeChange({price, amountGiven}) { + + const coins = { + // quarters: 0, + // dimes: 0, + // nickels: 0, + pennies: 0, + } + + let difference = amountGiven - price + + coins.pennies = difference + return coins + +} \ No newline at end of file diff --git a/src/makeChange.js b/src/makeChange.js index 59d89b1..05b1da0 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -1,3 +1,54 @@ +const coins = { + quarters: 0, + dimes: 0, + nickels: 0, + pennies: 0 +} +const takeQuarter = function(amountGiven, price){ + amountGiven = amountGiven - 25 + coins.quarters++ + return amountGiven +} +const takeDime = function(amountGiven, price){ + amountGiven = amountGiven - 10 + coins.dimes++ + return amountGiven +} +const takeNickel = function(amountGiven, price){ + amountGiven = amountGiven - 5 + coins.nickels++ + return amountGiven +} +const takePenny = function(amountGiven, price){ + amountGiven = amountGiven - 1 + coins.pennies++ + return amountGiven +} export default function makeChange({price, amountGiven}) { - // your code here + let results = {} + if(price === amountGiven) { + results.quarters = coins.quarters + results.dimes = coins.dimes + results.nickels = coins.nickels + results.pennies = coins.pennies + + coins.quarters = 0 + coins.dimes = 0 + coins.nickels = 0 + coins.pennies = 0 + return results + } + if(amountGiven - price >= 25){ + amountGiven = takeQuarter(amountGiven, coins) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(amountGiven - price >= 10){ + amountGiven = takeDime(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(amountGiven - price >= 5){ + amountGiven = takeNickel(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(amountGiven - price >= 1){ + amountGiven = takePenny(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + } }