Lab on Conditionals and DATE obj.
- More JS input/output
- Date JS Object
download folder, download the
lab07 folder and open
coffee.html file it in your code editor.
Where to put your JS code
use of the
Begin by adding code in
coffee.js so that it displays an alert with this text:
Welcome to the Coffee Consumption Calculator. We're here to help you gauge your coffee habit.
Then test the code by displaying the
coffee.html page in the browser, and make sure it displays the alert.
Each time you add more code to
coffee.js, save and then reload the page to test the changes.
Task 1: Coffee Cost
Ask the user for the cost of a cup of coffee they drink, and how many coffees they have per day (on average). Given this information, you will calculate how much money they spend on coffee per week and per month.
Use two prompts to collect these two pieces of data from the user. Save them in two variables. Remember to use meaningful names for your variables! It is the best way to self-document your code.
Calculate the amount the user spends on coffee per week, and per month (assume 4 weeks in a month).
Output the results
Output both results to the Console. Then write the results to the page itself.
Format the results
If your user enters an excessive amount of decimal points, for example
for cost, your results will also include excessive decimal points.
(as you did in the last assignment).
This method takes a single parameter to indicate how many decimal points you want. `
Pick an appropriate message
Based on how much the user spends on coffee per week, include a message to your user as part of your results. The message should correspond to the volume of their coffee consumption:
- Less than $10 a week:
That seems like a reasonable amount; enjoy!
- $10 or more, but less than $30:
Ok, that's a little pricey, but still not too bad.
- $30 or more, but less than $50:
Do you have any money leftover for food?
- $50 or more:
You'd better quit the habit before you go broke.