This lab requires you to write a complete program using a condition controlled l
ID: 3729662 • Letter: T
Question
This lab requires you to write a complete program using a condition controlled loop, a counter controlled loop, and an accumulator. The program is a follows:
Write a program that will allow a grocery store to keep track of the total number of bottles collected for seven days. The program should allow the user to enter the total number of bottles returned for seven days. The program will calculate the total number of bottles returned for the week and the amount paid out (the total returned times .10 cents). The output of the program should include the total number of bottles returned and the total paid out.
Write the JavaScript code to implement your algorithm
Explanation / Answer
<!DOCTYPE html>
<html>
<title>Grocery Store</title>
<head>
<script>
function main() {
alert("Welcome to Grocery Store");
var BottlesReturnedToday = 0;
var totalBottlesReturned = 0;
var totalAmount = 0;
var repeat = "y";
var counter = 1;
while (repeat == "y") {
counter = 1;
while(counter < 7){
BottlesReturnedToday = prompt("Enter the number of bottles returned on day " + counter);
totalBottlesReturned += parseInt(BottlesReturnedToday);
counter = counter +1;
}
totalAmount = totalBottlesReturned * 0.10;
alert("The total number of bottles returned is " + totalBottlesReturned);
alert("The total amount paid out is " + totalAmount);
repeat = prompt("Do you want to keep going? Enter y for yes");
}
}
//calls main
main();
alert("End of program");
</script>
</head>
<body>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.