Created
July 19, 2023 09:16
-
-
Save dan046/aa3107dc01b2b414ff7986c8f0f4b95e to your computer and use it in GitHub Desktop.
SuperSimpleDev Exercise 2 JavaScript Refresher - Numbers and Math
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // At a restaurant, you order 1 soup for $10, 3 burgers for $8 each, 1 ice cream for $5. | |
| const soup = 10 | |
| const burger = 8 | |
| const iceCream = 5 | |
| const totalCost = soup + (burger * 3) + iceCream | |
| console.log(totalCost) // Output: $39.00 | |
| // You're at a restaurant with 2 friends (3 people in total) and make the same order. Calculate how much each person pays. | |
| totalCost * 3 // Output: $117 | |
| // Divided to 3 people, since they ordered the same. | |
| totalCost * 3 / 3 // $39 | |
| // Calculate the total cost of a toaster ($18.50) and 2 shirts ($7.50). | |
| const toaster = 18.5 | |
| const shirt = 7.5 | |
| const total = toaster + (shirt * 2) | |
| console.log(total) // Output: $33.5 | |
| // Converting to cents version | |
| (1850 + (2 * 750)) / 100 // Output: $33.5 | |
| // Calculate a 10% tax for the total. | |
| const calculatedTax = total * 0.1 // 10% Tax: $3.35 | |
| const totalValue = total + calculatedTax | |
| console.log(totalValue) // $36.85 | |
| // Calculate a 20% tax for the total. | |
| const calculatedTax = total * 0.2 // 20% tax: $6.7 | |
| const totalValue = total + calculatedTax | |
| console.log(totalValue) // $40.2 | |
| // In th Amazon Project, go to the home page and add a toaster (18.99) to your cart so you have 1 basketball, 1 t-shirt and 1 toaster. Choose 4.99 shipping for the toaster. | |
| // Calculate the cost of the products (before shipping and taxes). Hint: Calculate in cents to avoid inaccuracies! | |
| // In cents | |
| (2095 + 799 + 1899) / 100 // Output: $47.93 total items without shipping. | |
| (2095 + 799 + (1899 + 499)) / 100 // Output: $52.92 total items with shipping from toaster Total before tax. | |
| // Calculate 10% tax. Hint: Use Math.round() | |
| Math.round((2095 + 799 + (1899 + 499) * 0.1) / 100 // Output: $5.29 | |
| // Total Order | |
| (2095 + 799 + (1899 + 499)) / 100 + 5.29 // Output: $58.21 | |
| // After finishing, remove the toaster from your cart and calculate again. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment