-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (75 loc) · 2.42 KB
/
script.js
File metadata and controls
90 lines (75 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*jslint browser:true */
"use strict";
function addMonths(elem) {
var annualUseKw=0, dailyUseKw=0, i=0, x=0;
var months=document.getElementById(elem).getElementsByTagName('input');
for(i=0; i<months.length; i++) {
x=Number(months[i].value);
annualUseKw += x;
} // end loop
dailyUseKw=annualUseKw/365;
return dailyUseKw;
} // end of function
function sunHours() {
var hrs;
var theZone=document.forms.solarForm.zone.selectedIndex;
theZone +=1; //array offset
switch(theZone) {
case 1:
hrs=6;
break;
case 2:
hrs=5.5;
break;
case 3:
hrs=5;
break;
case 4:
hrs=4.5;
break;
case 5:
hrs=4.2;
break;
case 6:
hrs=3.5;
break;
default:
hrs=0;
} //end switch
return hrs;
} // end function
function calculatePanel() {
var userChoice = document.forms.solarForm.panel.selectedIndex;
var panelOptions = document.forms.solarForm.panel.options;
var power = panelOptions[userChoice].value;
var name = panelOptions[userChoice].text;
var x=[power, name];
return x;
} // end function
function calculateSolar() {
var dailyUseKw = addMonths('mpc');
console.log(dailyUseKw);
var sunHoursPerDay = sunHours();
console.log(sunHoursPerDay);
var minKwNeeds = dailyUseKw/sunHoursPerDay;
console.log(minKwNeeds);
var realKwNeeds = minKwNeeds*1.25;
console.log(realKwNeeds);
var realWattNeeds = realKwNeeds * 1000;
console.log(realWattNeeds);
var panelInfo = calculatePanel();
var panelOutput = panelInfo[0];
var panelName = panelInfo[1];
console.log(panelOutput);
console.log(panelName);
var panelsNeeded = Math.ceil(realWattNeeds / panelOutput);
console.log(panelsNeeded);
var feedback="";
feedback += "<p>Based on your average daily use of "+Math.round(dailyUseKw)+" Kwh, you will need to purchase "+panelsNeeded+" "+panelName+" solar panels to offset 100% of your electricity bill.</p>";
feedback +="<h2>Additional Details</h2>";
feedback +="<p>Your average daily electricity consumption: "+Math.round(dailyUseKw)+" Kwh per day.</p>";
feedback +="<p>Average sunshine hours per day: "+sunHoursPerDay+" hours</p>";
feedback +="<p>Realistic watts needed per hour: "+Math.round(realWattNeeds)+" watts/hour.</p>";
feedback +="<p>The "+panelName+" panel you selected generates about "+panelOutput+" watts per hour.</p>";
document.getElementById('feedback').innerHTML=feedback;
} // end of function