For each line of input print a single line to standard output which is the change to be returned to the customer. In case the CH < PP, print out ERROR. If CH == PP, print out ZERO. For all other cases print the amount that needs to be returned. Some one please help.

const cashRegister = (price, cash) =>{ const UNIT_AMOUNT = { "PENNY": .01, "NICKEL": .05, "DIME": .10, "QUARTER": .25, "HALFDOLLAR": .50, "ONE": 1.00, "FIVE": 5.00, "TEN": 10.00, "TWENTY": 20.00, "Fifty": 50.00, "ONE HUNDRED": 100.00 } } if (cash < price) { return 'ERROR'; } if (cash === price) { return 'ZERO'; } let cashBack = cash - price; while (cashBack > .01) { if (cashBack >= 100.00) { console.log('ONE HUNDRED'); cashBack -= 100.00; } else { if (cashBack >= 50.00) { console.log('FIFTY'); cashBack -= 50.00; } else { if (cashBack >= 20.00) { console.log('TWENTY'); cashBack -= 20.00; } else { if (cashBack >= 10.00) { console.log('TEN'); cashBack -= 10.00; } else { if (cashBack >= 5.00) { console.log('FIVE'); cashBack -= 5.00; } else { if (cashBack >= 2.00) { console.log('TWO'); cashBack -= 2.00; } else { if (cashBack >= 1.00) { console.log('ONE'); cashBack -= 1.00; } else { if (cashBack >= .50) { console.log('HALF DOLLAR'); cashBack -= .50; } else { if (cashBack >= .25) { console.log('QUARTER'); cashBack -= .25; } else { if (cashBack >= .10) { console.log('DIME'); cashBack -= .10; } else { if (cashBack >= .05) { console.log('NICKEL'); cashBack -= .05; } else { console.log('PENNY'); cashBack -= .01; } } } } } } } } } } } console.log(','); } return cashBack 

submitted by /u/milli2323
[link] [comments]

from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/HI3sLzF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close