In: Computer Science
<!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- --> <title> TYPE YOUR NAME HERE</title> <script> // // A bug collector collects bugs every day for five days. Write a function that keeps // a running total of the number of bugs collected during the five days. The loop // should ask for the number of bugs collected for each day, and when the loop is // finished, the program should display the total number of bugs collected. // function countBugs() { ///////////////////////////////////////////////////////////////////////////////// // Insert your code between here and the next comment block. Do not alter // // any code in any other part of this file. // ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // Insert your code between here and the previous comment block. Do not alter // // any code in any other part of this file. // ///////////////////////////////////////////////////////////////////////////////// } alert('Over the past five days, ' + countBugs() + ' bugs were collected'); </script> </body> </html>
The modified html code is given below:-
<!DOCTYPE html>
<html>
<body>
<!-- replace the text below with your name!-->
<!-- -->
<!-- -->
<title> TYPE YOUR NAME HERE</title>
<script>
//
// A bug collector collects bugs every day for five days. Write a
function that keeps
// a running total of the number of bugs collected during the five
days. The loop
// should ask for the number of bugs collected for each day, and
when the loop is
// finished, the program should display the total number of bugs
collected.
//
function countBugs() {
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the next comment block. Do not
alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
var i= 0;
var day,sum = 0;
while(i < 5)
{
day = prompt("Enter the number of bugs for day " + (i
+ 1));
sum = sum + parseInt(day,10);
i++;
}
return sum;
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the previous comment block. Do
not alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
}
alert('Over the past five days, ' + countBugs() + ' bugs were
collected');
</script>
</body>
</html>
The screenshot of the changed code is given:-
Some screenshots from the output :-
Entering 5 continuously yields the following screenshot