diff --git a/week-05/tip-calculator-master/js/script.js b/week-05/tip-calculator-master/js/script.js index 8c39934..ba9dc21 100644 --- a/week-05/tip-calculator-master/js/script.js +++ b/week-05/tip-calculator-master/js/script.js @@ -42,4 +42,25 @@ function updateValues(event){ /** * Your code goes down here ... * @todo Write functions for calculateTipPerPerson() and calculateTotalPerPerson() - */ \ No newline at end of file + */ +function calculateTipPerPerson(totalValue, tipValue, peopleValue) { +totalValue = parseFloat(totalValue); +tipValue = parseFloat(tipValue); +peopleValue = parseFloat(peopleValue); + +let tipPerPerson = (totalValue * (tipValue / 100)) / peopleValue; + +tipPerPerson = tipPerPerson.toFixed(2); + +return tipPerPerson; +} + +function calculateTotalPerPerson(totalValue, tipValue, peopleValue) { +totalValue = parseFloat(totalValue); +tipValue = parseFloat(tipValue); +peopleValue = parseFloat(peopleValue); + +let totalPerPerson = (totalValue + (totalValue *(tipValue / 100))) / peopleValue; +totalPerPerson = totalPerPerson.toFixed(2); +return totalPerPerson; +} \ No newline at end of file