Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions src/comment from make_change.js
Original file line number Diff line number Diff line change
@@ -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

}
53 changes: 52 additions & 1 deletion src/makeChange.js
Original file line number Diff line number Diff line change
@@ -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})
}
}