Hi, I am Milky Girma. I had a really difficult encounter on how to pass the final JavaScript Project (Cash Register). It was extremely difficult. I had no choice but to refer from a website and see how to do it. I didn’t mean to plagiarize. I couldn’t even start on writing the code. The other projects were easy but I couldn’t solve this one so I want to know if I am plagiarizing.
const checkCashRegister = (price, cash, cid) => {
const amountForEachUnit = {
"PENNY": .01,
"NICKEL": .05,
"DIME": .10,
"QUARTER": .25,
"ONE": 1.00,
"FIVE": 5.00,
"TEN": 10.00,
"TWENTY": 20.00,
"ONE HUNDRED": 100.00
}
let totalCID = 0;
for (let element of cid) {
totalCID += element[1];
}
totalCID = totalCID.toFixed(2);
let changeToGive = cash - price;
const changeArray = [];
if (changeToGive > totalCID) {
return { status: "INSUFFICIENT_FUNDS", change: changeArray };
} else if (changeToGive.toFixed(2) === totalCID) {
return { status: "CLOSED", change: cid };
} else {
cid = cid.reverse();
for (let elem of cid) {
let temp = [elem[0], 0];
while (changeToGive >= amountForEachUnit[elem[0]] && elem[1] > 0) {
temp[1] += amountForEachUnit[elem[0]];
elem[1] -= amountForEachUnit[elem[0]];
changeToGive -= amountForEachUnit[elem[0]];
changeToGive = changeToGive.toFixed(2);
}
if (temp[1] > 0) {
changeArray.push(temp);
}
}
}
if (changeToGive > 0) {
return { status: "INSUFFICIENT_FUNDS", change: [] };
}
return { status: "OPEN", change: changeArray};
}
when in doubt, delete the project and do it again on your own, if you need search for specific things (e.g. how to copy an array, how to test a string etc), but not the solution to the problem
OK, I will try my best. Thanks for replying!
Besides, the point is not just to pass the test. The point is to learn how to pass the test. If you just copy code you likely do not fully understand you will have learned nothing, or very little. So you are really just cheating yourself.
If you need help, use the Get Help > Ask for Help button on the challenge. It will post your code and you can ask any questions you have. You definitely have a choice.
Thanks guys. The forum really replies fast.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.