@Christonja/

Cash Register

JavaScript

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.2894899153272381","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"LyogSmF2YVNjcmlwdCBBbGdvcml0aG1zIGFuZCBEYXRhIFN0cnVjdHVyZXMgUHJvamVjdHM6IENhc2ggUmVnaXN0ZXI6IENoYWxsZW5nZSBkZXNpZ25lZCBieSBGcmVlQ29kZUNhbXAsIHNvbHV0aW9uIGRlcml2ZWQgY29tcGxldGVseSBmcm9tIG15IGxlYXJuaW5nIG9idGFpbmVkIHRoYW5rcyB0byBGcmVlQ29kZUNhbXAgYW5kIG90aGVyIHNvdXJjZXMgb24gdGhlIGludGVybmV0LiBGdW5jdGlvbiBjYWxscyBwcm92aWRlZCBieSBGcmVlQ29kZUNhbXAgYXMgd2F5cyB0byB0ZXN0IHRoZSBhbGdvcml0aG0gKi8KCmZ1bmN0aW9uIGNoZWNrQ2FzaFJlZ2lzdGVyKHByaWNlLCBjYXNoLCBjaWQpIHsKICB2YXIgY2hhbmdlRHVlID0gY2FzaCAtIHByaWNlOyAvL2NoYW5nZSByZXF1aXJlZCBmcm9tIGNhc2ggZ2l2ZW4gbWludXMgY29zdCBvZiBwdXJjaGFzZQogIHZhciB0b3RhbENoYW5nZSA9IHsgc3RhdHVzOiAiT1BFTiIsIGNoYW5nZTogW10gfTsgLy9uZXcgb2JqZWN0IHRoYXQgaXMgaW5pdGlhbGlzZWQgd2l0aCBhbiBvcGVuIHN0YXR1cyBhbmQgZW1wdHkgYXJyYXkgYnkgZGVmYXVsdAogIHZhciBjaGFuZ2VDb3VudCA9IDA7IC8vY291bnRlcgogIHZhciB0ZW1wQ2hhbmdlOyAvL3RlbXBvcmFyeSB2YXJpYWJsZSB0byBhc3Npc3Qgd2l0aCBkZWNyZW1lbnRpbmcgdGhlIGNoYW5nZSBkdWUsIGhvd2V2ZXIgaXQgY291bGQgYmUgaW1wbGVtZW50ZWQg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WyJUV0VOVFkiLCAwXSwgWyJPTkUgSFVORFJFRCIsIDBdXSkgLy9zaG91bGQgcmV0dXJuIHtzdGF0dXM6ICJJTlNVRkZJQ0lFTlRfRlVORFMiLCBjaGFuZ2U6IFtdfS4KY2hlY2tDYXNoUmVnaXN0ZXIoMTkuNSwgMjAsIFtbIlBFTk5ZIiwgMC41XSwgWyJOSUNLRUwiLCAwXSwgWyJESU1FIiwgMF0sIFsiUVVBUlRFUiIsIDBdLCBbIk9ORSIsIDBdLCBbIkZJVkUiLCAwXSwgWyJURU4iLCAwXSwgWyJUV0VOVFkiLCAwXSwgWyJPTkUgSFVORFJFRCIsIDBdXSkgLy9zaG91bGQgcmV0dXJuIHtzdGF0dXM6ICJDTE9TRUQiLCBjaGFuZ2U6IFtbIlBFTk5ZIiwgMC41XSwgWyJOSUNLRUwiLCAwXSwgWyJESU1FIiwgMF0sIFsiUVVBUlRFUiIsIDBdLCBbIk9ORSIsIDBdLCBbIkZJVkUiLCAwXSwgWyJURU4iLCAwXSwgWyJUV0VOVFkiLCAwXSwgWyJPTkUgSFVORFJFRCIsIDBdXX0="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* JavaScript Algorithms and Data Structures Projects: Cash Register: Challenge designed by FreeCodeCamp, solution derived completely from my learning obtained thanks to FreeCodeCamp and other sources on the internet. Function calls provided by FreeCodeCamp as ways to test the algorithm */

function checkCashRegister(price, cash, cid) {
  var changeDue = cash - price; //change required from cash given minus cost of purchase
  var totalChange = { status: "OPEN", change: [] }; //new object that is initialised with an open status and empty array by default
  var changeCount = 0; //counter
  var tempChange; //temporary variable to assist with decrementing the change due, however it could be implemented without this
  var tempCash; //gets the money out of the cash drawer for the currency unit we're working with
  var cashDrawer = totalCash(cid); //cashDrawer is initialised to the return of a function that calculates the total cash in the drawer
  //if cash-in-drawer is less than the change due, return insufficent funds, not needed however saves the code from running through further to the end of the else statement if this is provided up top. 
  if (cashDrawer < changeDue) {
    console.log({ status: "INSUFFICIENT_FUNDS", change: [] });
    return { status: "INSUFFICIENT_FUNDS", change: [] };
  //if cash-in-drawer is equal to the change due, return the value of the cash in drawer and close it as it's been emptied by the customer
  } else if (cashDrawer == changeDue) {
    console.log({status: "CLOSED", change: cid });
    return {status: "CLOSED", change: cid };
  } else {
    //else run through each currency unit pushing the amount of cash available at each currency unit into the totalChange object array until the changeDue in zero
    tempCash = cid[8][1]; //get the currency unit from the cash drawer
    while (changeDue >= 100 && tempCash > 0) { //while changeDue is greater than currency unit and while there's cash available at that currency unit
      tempChange = changeDue - 100; //decrement changeDue
      changeCount++; //count the notes/coins
      changeDue = tempChange; //changeDue assigned as the decrement
      tempCash-=100; //decrement tempCash as there's now less money in the cash drawer
    } 

    //if the currency unit was used then push the times it was used onto the totalchange array and multiply by the currency unit value to be equal to the note/coin value
    if (changeCount > 0) {
      totalChange.change.push(["ONE HUNDRED", changeCount * 100]);
    }
    //repeat this process for each denomination
    tempCash = cid[7][1];
    changeCount = 0;
    while (changeDue >= 20 && tempCash > 0) {
      tempChange = changeDue - 20;
      changeCount++;
      changeDue = tempChange;
      tempCash-=20;
    } 
    if (changeCount > 0) {
      totalChange.change.push(["TWENTY", changeCount * 20]);
    }
    tempCash = cid[6][1];
    changeCount = 0;
    while (changeDue >= 10 && tempCash > 0) {
      tempChange = changeDue - 10;
      changeCount++;
      changeDue = tempChange;
      tempCash-=10;
    } 
    if (changeCount > 0) {
      totalChange.change.push(["TEN", changeCount * 10]);
    }
    tempCash = cid[5][1];
    changeCount = 0;
    while (changeDue >= 5 && tempCash > 0) {
      tempChange = changeDue - 5;
      changeCount++;
      changeDue = tempChange;
      tempCash-=5;
    } 
    if (changeCount > 0) {
      totalChange.change.push(["FIVE", changeCount * 5]);
    }
    tempCash = cid[4][1];
    changeCount = 0;
    while (changeDue >= 1 && tempCash > 0) {
      tempChange = changeDue - 1;
      changeCount++;
      changeDue = tempChange;
      tempCash-=1;
    } 
    if (changeCount > 0) {
      totalChange.change.push(["ONE", changeCount * 1]);
    }
    tempCash = cid[3][1];
    changeCount = 0;
    while (changeDue >= 0.25 && tempCash > 0) {
      tempChange = changeDue - 0.25;
      changeCount++;
      changeDue = tempChange;
      tempCash-=0.25;
    } 
    if (changeCount > 0) {
      totalChange.change.push(["QUARTER", changeCount * 0.25]);
    }
    tempCash = cid[2][1];
    changeCount = 0;
    while (changeDue >= 0.1 && tempCash > 0) {
      tempChange = changeDue - 0.1;
      changeCount++;
      changeDue = tempChange;
      tempCash-=0.1;
    } 
    if (changeCount > 0) {
      totalChange.change.push(["DIME", changeCount * 0.1]);
    }
    tempCash = cid[1][1];
    changeCount = 0;
    while (changeDue >= 0.05 && tempCash > 0) {
      tempChange = changeDue - 0.05;
      changeCount++;
      changeDue = tempChange;
      tempCash-=0.05;
    } 
    if (changeCount > 0) {
      totalChange.change.push(["NICKEL", changeCount * 0.05]);
    }
    tempCash = cid[0][1];
    changeCount = 0;
    //if change due is more than what's left in the cash drawer at this point then return insufficient, the customer gets nothing even though they almost got most of their money back
    if (changeDue > tempCash) {
      return { status: "INSUFFICIENT_FUNDS", change: [] };
    // else if change is still due, we know there's money in the cash drawer enough to cover it, and we also know we've exhausted the other currency units, therefore, supply the customer with the remainder of the change in penny's
    } else if (changeDue > 0){
      var remainder = 0;
      remainder = Number(changeDue.toFixed(2)); //fixed the remainder to two decimal places to remove imprecision
      totalChange.change.push(["PENNY", remainder]); //push penny's onto the array
    }
    console.log(totalChange);
    return totalChange;
  }
  //function to calculate total cash in cash drawer
  function totalCash(total) {
    var temp = 0;
    for (var x = 0; x < total.length; x++) {
      temp+=total[x][1];
    }    return temp.toFixed(2); //returns the total fixed to 2 decimal places to prevent imprecision
  }

}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]) //should return an object.
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]) //should return {status: "OPEN", change: [["QUARTER", 0.5]]}.
checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]) //should return {status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]}.
checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]) //should return {status: "INSUFFICIENT_FUNDS", change: []}.
checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]) //should return {status: "INSUFFICIENT_FUNDS", change: []}.
checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]) //should return {status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]}
Native Browser JavaScript