/* FILE NAME: coffee.js WRITTEN BY: DATE: PURPOSE: */ /* Gets the user's inputs from the web page. Calculates monthly costs. Given that, decides on the appropriate second message. Puts these two messages on the page */ function giveFeedback() { // get the input for cost of coffee var costPerCup = parseFloat(document.getElementById("costPerCupID").value); var cupsPerDay = parseFloat(document.getElementById("cupsPerDayID").value); // calculate weekly cost var amount = costPerCup * cupsPerDay * 7; //7 days in a week //produce the messages to print on the page var message1 = "Every week you spend $" + amount.toFixed(2) + " on coffee."; //decide the second message to present, depending on the spent amount var message2 = "You'd better quit the habit before you go broke."; //default message //it will show when amount is more or equal to 50. if (amount < 10) { message2 = "That seems like a reasonable amount; enjoy!"; } else if (amount < 30) { message2 = "Ok, that's a little pricey, but still not too bad."; } else if (amount < 50) { message2 = "Do you have any money left over for food?"; } // display messages on the page document.getElementById("resultsID").innerHTML = message1 + "
" + message2; }