Question

7.11 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track...

7.11 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording the number of miles driven and the number of gallons used for each tankful. Develop a script that will take as input the miles driven and gallons used (both as integers) for each tankful. The script should calculate and output HTML5 text that displays the number of miles per gallon obtained for each tankful and the combined number of miles per gallons obtained for all tankfuls up to this point. Use prompt dialogs to obtain the data from the user. [Scroll down or expand this text area to view the rest of this assignment.]

Note 1: The "combined number of miles per gallon obtained for all tankfuls up to this point" is the total miles driven divided by the total gallons used.

Note 2: Chrome will not display the output of writeln until the end of the script. So, don't worry about this. I.e., it is OK that the output is delayed in this way.

7.12 Develop a script that will determine whether a department-store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
a) Account number
b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer's account this month
e) Allowed credit limit

The script should input each of these facts from a prompt dialog as an integer, calculate the new balance (= beginning balance + charges - credits), display the new balance and determine whether the new balance exceeds the customer's credit limit. For customers whose credit limit is exceeded, the script should output HTML5 text that displays the message "Credit limit exceeded."

Create two .html files, one for each exercise.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

tankful.html:

<html>

<body onload="myFunction()">

<h2>Number of Miles per Gallon</h2>

<p id="demo"/>

<script>

function myFunction() {

var txt;

var miles = prompt("Please enter the number of miles driven: (only integers)");

var gallons = prompt("Please enter the number of gallons used: (only integers)");

if (miles == null || miles == "" || miles == 0) {

txt = "User cancelled the prompt.";

} else {

txt = "Number of Miles per Gallon: <b>" + (miles/gallons) + "</b>";

}

document.getElementById("demo").innerHTML = txt;

}

</script>

</body>

</html>

credit-report.html:

<html>

<body onload="myFunction()">

<h2>Credit Report</h2>

<p id="account-number"/>

<p id="new-balance"/>

<p id="credit-report"/>

<script>

function myFunction() {

var txt;

var accountNumber = prompt("Please enter the account number: (integers only)");

var balanceAtBeginning = prompt("Please enter the balance at the beginning of the month: ");

var totalCharges = prompt("Total of all items charged by this customer this month: ");

var totalCredits = prompt("Total of all credits applied to this customer's account this month:");

var allowedCreditLimit = prompt("Please enter the Allowed credit limit: (integers only)");

txt = "Account Number: <b>" + accountNumber + "</b>";

document.getElementById("account-number").innerHTML = txt;

  

var newBalance = (balanceAtBeginning + totalCharges - totalCredits);

txt = "New Balance Amount: <b>" + newBalance + "</b>";

document.getElementById("new-balance").innerHTML = txt;

  

if (newBalance > allowedCreditLimit) {

txt = "Credit limit exceeded.";

} else {

txt = "Credit limit not exceeded.";

}

document.getElementById("credit-report").innerHTML = txt;

}

</script>

</body>

</html>

Add a comment
Know the answer?
Add Answer to:
7.11 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...

    Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls....

  • Drivers are concerned with the mileage their automobiles get. One driver has kept track of several...

    Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...

  • Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that inputs the miles driven and gallons us

    Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that inputs the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up to this point.

  • Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...

    Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of gasoline by recording miles driven and gallons used for each tank. Develop a program using a while loop that will input the miles driven and the gallons used for each tank. The program should calculate and display the miles per gallon obtained for each tank. After processing all input information, the program should calculate and print the overall miles per gallon...

  • The code should be written in HTML 5. Thanks! Develop a script that will determine whether...

    The code should be written in HTML 5. Thanks! Develop a script that will determine whether a department-store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: a) Account number b) Balance at the beginning of the month c) Total of all items charged by this customer this month d) Total of all credits applied to this customer's account this month e) Allowed credit limit The script should input each of...

  • i need to Develop a script in java script that will determine whether a department-store customer...

    i need to Develop a script in java script that will determine whether a department-store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: a) Account number b) Balance at the beginning of the month c) Total of all items charged by this customer this month d) Total of all credits applied to this customer's account this month e) Allowed credit limit The script should input each of these facts from...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • Write a Java application that determines whether any of several department store customers has exceeded the...

    Write a Java application that determines whether any of several department store customers has exceeded the credit limit on a charge account. For each customer, the following facts are inputted: -Balance at beginning of month -Total amount of all items charged by the customer this month -Total amount of all credits applied to the customer’s account this month -Allowed credit limit Use the value of -1 as a sentinel value to quit the program. The program should input all these...

  • Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a...

    Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the name and the price per unit for two different candies. Then, the customer is allowed to order as many units of each of the two candies as they would like. Lastly, an invoice (report) is generated (displayed to the screen) under the following rules: All units up to...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT