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

Write the JavaScript code for the following programming problem based on the pse

ID: 3739175 • Letter: W

Question

Write the JavaScript code for the following programming problem based on the pseudocode below

The Pseudocode

Module main()

            //Declare local variables

            Declare String 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”]

While endProgram == “no”

                        //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[])

            Declare Integer counter

            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[])

            Declare Integer counter

            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[])

            Declare Integer counter

            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

Explanation / Answer

<!DCOTYPE html>

<html>

<head>

<script>

var notGreenCost=[];

var goneGreenCost=[];

var savings=[];

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

function main()

{

//Declare local variables

var endProgram = "no";

while(endProgram == "no")

{

//function calls

getNotGreen(notGreenCost, months);

getGoneGreen(goneGreenCost, months);

energySaved(notGreenCost, goneGreenCost, savings);

displayInfo(notGreenCost, goneGreenCost, savings, months);

endProgram=prompt("Do you want to end the program? Yes or no");

}

// End While

}

//End Module

function getNotGreen(notGreenCosts, months)

{

var counter;

counter = 0;

while(counter < 12)

{

notGreenCosts[counter]= prompt( "Enter NOT GREEN energy costs for "+ months[counter]);

counter = counter + 1;

}

}

//End Module

function getGoneGreen(goneGreenCost, months)

{

var counter;

counter = 0;

while(counter < 12)

{

goneGreenCost[counter] = prompt("Enter GONE GREEN energy costs for" + months[counter]);

counter = counter + 1;

}

//End While

}

//End Module

function energySaved(notGreenCost,goneGreenCost, savings)

{

var counter;

counter = 0;

console.log(goneGreenCost);

while(counter < 12)

{

savings[counter] = notGreenCost[counter]-goneGreenCost[counter];

counter = counter + 1;

}

// End While

}

//End Module

function displayInfo(notGreenCost,goneGreenCost, savings, months)

{

var counter = 0;

while(counter < 12)

{

//to display as alert

alert("Information for " + months[counter]);

// to display on console of the browser uncomment below line

// console.log("Information for " + months[counter]);

alert("Savings $ "+savings[counter]);

// to display on console of the browser uncomment below line

// console.log("Savings $ "+savings[counter]);

alert("Not Green Costs $"+ notGreenCost[counter]);

// to display on console of the browser uncomment below line

// console.log("Not Green Costs $"+ notGreenCost[counter]);

alert("Gone Green Costs $"+ goneGreenCost[counter]);

// to display on console of the browser uncomment below line

// console.log("Gone Green Costs $"+ goneGreenCost[counter]);

counter=counter+1;

}

//End While

}

//End Module

main();

</script>

</head>

<body>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote