Beginner activities based on a simple Tip Calculator.
Javascript features used in this script:
To run tip-calculator.js from the browser:
-
Download or clone this Gist into your workspace;
-
In this new directory, create a valid
index.htmlfile; -
In the
<head>ofindex.html, link totip-calculator.jswith a<script>tag:<script src="tip-calculator.js" type="module">
-
Run
index.htmlin the browser of your choice; -
Open the Web Console to view the output.
Refactor this script to add/improve features:
- Declare a new
tipPercentagevariable that outputs18%(or similar) and log that new variable in theconsole.log(). - Declare a new
paymentTotalvariable and set its value to thebillTotalplustipAmountand log it to the console. - Using Template literals, log a complete sentence to the console that uses the following variables:
billTotaltipPercentagepaymentTotal- Example: "18% tip on $20 is $23.60"
- The last time you checked, there's no coin for
$0.00001. Use theMath.round()method to round thetipto the nearest cent.- Hint: You can multiply by 100, then round, then divide by 100 to round to the nearest cent.