-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_scripts.js
174 lines (150 loc) · 7.04 KB
/
my_scripts.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
players is an array to hold each player's information.
Fields:
name - Football player's name
img - The relative/absolute path to the image file.
alt - The alternative text that describes the image.
year - The student's year in college (Freshman, Sophomore, Junior, Senior).
major- The student's current college major.
games_played - The number of football games the student has played for the Buffs.
pass_yards - The total number of passing yards in the student's football career for the Buffs.
rushing_yards - The total number of rushing yards in the student's football career for the Buffs.
receiving_yards - The total number of receiving yards in the student's football career for the Buffs.
*/
var players = [{name:"John Doe", img: "../resources/img/player1.jpg", alt:"Image of Player 1", year:"Sophomore", major:"Art", games_played: 23, pass_yards: 435, rushing_yards: 200, receiving_yards: 88},
{name:"James Smith", img: "../resources/img/player2.jpg", alt:"Image of Player 2", year:"Junior", major:"Science", games_played: 17, pass_yards: 192, rushing_yards: 102, receiving_yards: 344},
{name:"Samuel Phillips", img: "../resources/img/player3.jpg", alt:"Image of Player 3", year:"Freshman", major:"Math", games_played: 8, pass_yards: 35, rushing_yards: 70, receiving_yards: 98},
{name:"Robert Myers", img: "../resources/img/player4.jpg", alt:"Image of Player 4", year:"Senior", major:"Computer Science", games_played: 31, pass_yards: 802, rushing_yards: 375, receiving_yards: 128}];
/*
Registration Page:
viewStudentStats(id, toggle) method
parameters:
id - The css id of the html tag being updated.
toggle -
0 - hide the html tag
1 - make the html tag visible
purpose: This method will accept the id of an html tag and a toggle value.
The method will then set the html tag's css visibility and height.
To hide the html tag (toggle - 0), the visibility will be set to hidden and
the height will be set to 0.
To reveal the html tag (toggle - 1), the visibility will be set to visible and
the height will be set to auto.
*/
function viewStudentStats(id, toggle)
{
if (toggle === 1){
document.getElementById(id).style.visibility = "visible";
document.getElementById(id).style.height = "auto";
}
else{
document.getElementById(id).style.visibility = "hidden";
document.getElementById(id).style.height = 0;
}
}
/*
Home Page:
changeColor(color) method
parameter:
color- A css color
purpose: This method will set the html body's background color to the
provided parameter.
*/
function changeColor(color)
{
document.body.style.background=color;
}
/*
Football Season Stats Page:
loadStatsPage method:
parameters: none
purpose: This method will iterate through the stats table and
do the following:
1. Read through each row of the table & determine which team won
the game.
2. Update the winner column to the name of the winning team.
3. Keep track of the number of wins/losses for the Buffs.
4. Update the second table to show the total number of wins/losses for the Buffs.
*/
function loadStatsPage(){
var table = document.getElementById("stats_table");//Retrieve our table element
var row_counter;//Keeps track of our row index
var col_counter;//Keeps track of our column index
var opp_score;
var home_score;
var wins = 0;
var losses = 0;
for(row_counter = 2; row_counter < table.rows.length; row_counter++)
{//Outer for loop iterates over each row
home_score = table.rows[row_counter].cells[2].innerHTML;
opp_score = table.rows[row_counter].cells[3].innerHTML;//Read in a cells current value
if(home_score > opp_score){
table.rows[row_counter].cells[4].innerHTML = "CU Boulder";
wins++;
}
else{
table.rows[row_counter].cells[4].innerHTML = table.rows[row_counter].cells[1].innerHTML;
losses++;
}
}
document.getElementById("wins").innerHTML = wins;
document.getElementById("losses").innerHTML = losses;
}
/*
Football Player Information Page
loadPlayersPage method:
parameters: none
purpose: This method will populate the dropdown menu to allow the
user to select which player's information to view.
To handle this, you will need to iterate through the players array
and do the following for each player:
1. Create an anchor tag
2. Set the href to "#", this will make sure the
anchor tag doesn't change pages
3. Set the onclick to call switchPlayers method
(this will need to pass in the index inside the players array)
4. Set the anchor tag's text to the player's name.
After setting all of the anchor tags, update the innerHTML of the dropdown menu.
As a note, the id for the dropdown menu is player_selector.
*/
function loadPlayersPage(){
plen = players.length;
var drpdwn = document.getElementById("player_selector");
var tag = " "
for (i = 0; i < plen; i++) {
tag +='<button onclick= "switchPlayers('+i+')">'+players[i].name+'</button><br/>'
drpdwn.innerHTML = tag;
}
}
/*
switchPlayers(playerNum) method:
parameters:
playerNum - The index of the football player in the players array.
purpose:
This method will update the the spans on the player's information pageX
and calculate the average passing, rushing, and receiving yards.
Span ids:
p_year - the player's year in college
p_major - the player's major in college
g_played - the number of games played for Buffs
player_img - the player's photo (must set src and alt)
p_yards - the number of passing yards
r_yards - the number of rushing yards
rec_yards - the number of receiving yards
Calculated values:
avg_p_yards - the average number of passing yards for the player's Buff career
avg_r_yards - the average number of rushing yards for the player's Buff career
avg_rec_yards - the average number of receiving yards for the player's Buff career
*/
function switchPlayers(playerNum){
curplayer = players[playerNum];
document.getElementById("p_year").innerHTML = curplayer.year;
document.getElementById("p_major").innerHTML = curplayer.major;
document.getElementById("g_played").innerHTML = curplayer.games_played;
document.getElementById("player_img").src = curplayer.img;
document.getElementById("p_yards").innerHTML = curplayer.pass_yards;
document.getElementById("r_yards").innerHTML = curplayer.rushing_yards;
document.getElementById("rec_yards").innerHTML = curplayer.receiving_yards;
document.getElementById("avg_p_yards").innerHTML = (curplayer.pass_yards/curplayer.games_played).toFixed(2);
document.getElementById("avg_r_yards").innerHTML = (curplayer.rushing_yards/curplayer.games_played).toFixed(2);
document.getElementById("avg_rec_yards").innerHTML = (curplayer.receiving_yards/curplayer.games_played).toFixed(2);
}