Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the Flowchart, and JavaScript code for the following programming problem b

ID: 3771454 • Letter: W

Question

Write the Flowchart, and JavaScript code for the following programming problem based on the pseudocode below.

Last year, a local college implemented rooftop gardens as a way to promote energy efficiency and save money. Write a program that will allow the user to enter the energy bills from January to December for the year prior to going green. Next, allow the user to enter the energy bills from January to December of the past year after going green. The program should calculate the energy difference from the two years and display the two years worth of data, along with the savings.

Hints: Create three arrays of size 12 each. The first array will store the first year of energy costs, the second array will store the second year after going green, and the third array will store the difference. Also, create a string array that stores the month names. These variables might be defined as follows:

notGreenCost = [];

goneGreenCost = [];

savings = [];

You will also need an array to hold the month names:

months = [“January”, “February”, “March “, “April “, “May “, “June “, “July “, “August”, “September”, “October”, “November”, “December”];

The extra spaces in March – June help in lining up the output shown below.

Base on this Pseudocode:

Module main()

   //Declare local variables

   Declare endProgram = “no”

   While endProgram == “no”

       Declare Real notGreenCost[12]

       Declare Real goneGreenCost[12]

       Declare Real savings[12]

Declare String months[12] = “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”

      

       //function calls

       getNotGreen(notGreenCost, months)

       getGoneGreen(goneGreenCost, months)

       energySaved(notGreenCost, goneGreenCosts, savings)

       displayInfo(notGreenCost, goneGreenCosts, savings, months)

  

       Display “Do you want to end the program? Yes or no”

       Input endProgram

   End While

End Module

Module getNotGreen(Real notGreenCost[], String months[])

   Set counter = 0

   While counter < 12

       Display “Enter NOT GREEN energy costs for”, months[counter]

       Input notGreenCosts[counter]

       Set counter = counter + 1

   End While  

End Module

Module getGoneGreen(Real goneGreenCost[], String months[])

   Set counter = 0

   While counter < 12

       Display “Enter GONE GREEN energy costs for”, months[counter]

       Input goneGreenCosts[counter]

       Set counter = counter + 1

   End While  

End Module

Module energySaved(Real notGreenCost[], Real goneGreenCost[], Real savings[])

   Set counter = 0

   While counter < 12

       Set savings[counter] = notGreenCost[counter] – goneGreenCost[counter]

       Set counter = counter + 1

   End While

End Module

Module displayInfo(Real notGreenCost[], Real goneGreenCost[], Real savings[], String months[])

   Set counter = 0

   While counter < 12

       Display “Information for”, months[counter]

       Display “Savings $”, savings[counter]

       Display “Not Green Costs $”, notGreenCost[counter]

       Display “Gone Green Costs $”, goneGreenCost[counter]

   End While

End Module

Please Create the JavaScript code and a Flowchart. (No Java libraries!!!!)

This needs to be a program that shows up in a browser window (html) and it is JavaScript only (no libraries)

Explanation / Answer

<!DOCTYPE html>
<html lang="en">
    <head> <!-- open of head -->

<meta charset="utf-8">
<title> Going Green Energy</title>
<link rel="shortcut icon" href="me.jpg">

</head>

<body> <!-- beginning of the body section -->

<header>

   <h1> Going Green Statstics </h1>

</header>

   <script type="text/javascript">


   var noOfMonths = 3;
   function goGreenStats() {
     
       var notGreenCost = [];

       var goneGreenCost = [];
       var savings = [];
     
       var months = ["January", "February", "March ", "April ", "May ", "June ", "July ", "August", "September", "October", "November", "December"];
  
       getCosts(notGreenCost, months, "NOT GREEN");
       getCosts(goneGreenCost, months, "GREEN");
     
       var i = 0;
       var total = 0;
       var diff = 0;
       var text = "Month    Not Go Green    Go Green   Savings " ;
       for(i = 0; i <noOfMonths; i++) {
           diff = notGreenCost[i] - goneGreenCost[i];
           total += diff;
           text += months[i]+"    "+notGreenCost[i]+"       "+goneGreenCost[i]+"    "+diff+ " ";
       }
     
       alert(text);
   }

   function getCosts(costArr, months, mode) {
       var i = 0;
       var input = 0;
       for(i =0; i < noOfMonths; i++ ) {
              input = prompt("Enter "+mode+" energy costs for "+months[i], "");
              costArr[i] = input;
       }
   }

   goGreenStats();
</script>

   <div id="content">
   </div>
<script>

</script>

   </body>

</html>

Dr Jack
Hire Me For All Your Tutoring Needs
Quick quotes • Clear explanations • Study support
Chat Now And Get Quote