diff --git a/week-05/.gitignore b/week-05/.gitignore new file mode 100644 index 0000000..c667e8f --- /dev/null +++ b/week-05/.gitignore @@ -0,0 +1,27 @@ +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk \ No newline at end of file diff --git a/week-05/README.md b/week-05/README.md new file mode 100644 index 0000000..28aa4ec --- /dev/null +++ b/week-05/README.md @@ -0,0 +1,18 @@ +# Tip Calculator +An exercise in JavaScript function definitions and return values. Course: DMD 3475. + +## Introduction +Our tip calculator application is almost complete. Our function named `updateValues()` will fetch the values that were input by the user. + +At that point, the values are passed as arguments to two functions named `calculateTipPerPerson()` and `calculateTotalPerPerson()`. The values that are returned by each function are used to update the DOM. + +## Instructions + +1. Define both required functions: `calculateTipPerPerson()` and `calculateTotalPerPerson()`. +2. Each function should accept the 3 arguments being passed to them within the `updateValues()` function. +3. Using those values, calculate and return the appropriate answer. +4. Extra credit: Properly round the dollars and cents that are returned by your functions. + +## Helpful Information +* Search Google for "Tip Calculator" to see the desired functionality for this application. +* The `calculateTotalPerPerson()` function should return a value that includes the tip. \ No newline at end of file diff --git a/week-05/css/main.css b/week-05/css/main.css new file mode 100644 index 0000000..6bfd182 --- /dev/null +++ b/week-05/css/main.css @@ -0,0 +1,28 @@ +body { + display: flex; + align-items: center; + justify-content: center; + min-height: 100vh; +} + +.card { + width: 400px; + max-width: 100%; +} + +.card-image img { + height: 100px; + object-fit: cover; + object-position: center; +} + +.card-content .row { + margin: 0; +} + + +.card .card-image .card-title { + font-weight: bold; + text-shadow: 2px 2px 3px black; + padding-bottom: 12px; +} \ No newline at end of file diff --git a/week-05/images/bg.jpg b/week-05/images/bg.jpg new file mode 100644 index 0000000..7a1fb9a Binary files /dev/null and b/week-05/images/bg.jpg differ diff --git a/week-05/index.html b/week-05/index.html new file mode 100644 index 0000000..368400e --- /dev/null +++ b/week-05/index.html @@ -0,0 +1,58 @@ + + + + + + Tip Calculator + + + + + + + +
+
+ + Tip Calculator +
+
+
+
+
+
+ attach_money + + +
+
+ pie_chart + + +
+
+ group_add + + +
+
+
+
+
+
+
+
+ Tip (per person): $ +
+
+ Total (per person): $ +
+
+
+
+ + + + + + \ No newline at end of file diff --git a/week-05/js/script.js b/week-05/js/script.js new file mode 100644 index 0000000..edbafe7 --- /dev/null +++ b/week-05/js/script.js @@ -0,0 +1,59 @@ +/** + * Get references to each of the form inputs + */ +let total = document.querySelector('#total'); +let tip = document.querySelector('#tip'); +let people = document.querySelector('#people'); + +/** + * Whenever the fields are updated, we call + * the updateValues function. + */ +total.addEventListener('change', updateValues); +total.addEventListener('keyup', updateValues); +tip.addEventListener('change', updateValues); +tip.addEventListener('keyup', updateValues); +people.addEventListener('change', updateValues); +people.addEventListener('keyup', updateValues); + +/** + * We will need references for the span tags + * that we will use to output our results. + */ +let tipOutput = document.querySelector(".tipOutput"); +let totalOutput = document.querySelector(".totalOutput"); + +/** + * This function is run every time an input is changed + * by a user. + */ +function updateValues(event){ + + // Get the latest values from our form inputs + let totalValue = total.value; + let tipValue = tip.value; + let peopleValue = people.value; + + // Update the values on the screen + tipOutput.innerText = calculateTipPerPerson(totalValue, tipValue, peopleValue); + totalOutput.innerText = calculateTotalPerPerson(totalValue, tipValue, peopleValue); +} + +/** + * Your code goes down here ... + * @todo Write functions for calculateTipPerPerson() and calculateTotalPerPerson() + */ + +function calculateTipPerPerson(totalValue, tipValue, peopleValue) { + tipValue /= 100; + let tipPerPerson = (totalValue*tipValue)/peopleValue; + tipPerPerson = tipPerPerson.toFixed(2) + return tipPerPerson; +} + +function calculateTotalPerPerson (totalValue, tipValue, peopleValue) { + tipValue = 1 + (tipValue/100); + let totalPerPerson = (totalValue*tipValue)/peopleValue; + totalPerPerson = totalPerPerson.toFixed(2) + return totalPerPerson; +} \ No newline at end of file