[go: up one dir, main page]

0% found this document useful (0 votes)
6 views3 pages

AP CS Code PDF

The document outlines a program that retrieves basketball player statistics and displays the top players based on points, assists, and championship wins. It includes a function to sort players by a selected statistic and update the display when a user selects a stat. Additionally, it handles user interactions for confirming selections and returning to the home screen.

Uploaded by

connorkipling52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

AP CS Code PDF

The document outlines a program that retrieves basketball player statistics and displays the top players based on points, assists, and championship wins. It includes a function to sort players by a selected statistic and update the display when a user selects a stat. Additionally, it handles user interactions for confirming selections and returning to the home screen.

Uploaded by

connorkipling52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

// Set initial screen and hide all stat text elements

setScreen("HomeScreen");
// Get data from the "Basketball Player Statistics" table
var points = getColumn("Basketball Player Statistics", "Points");
var assists = getColumn("Basketball Player Statistics", "Assists");
var wins = getColumn("Basketball Player Statistics", "Championship Wins");
var playerName = getColumn("Basketball Player Statistics", "Player name");
// Create a list of player objects with stats
var players = [];
for (var i = 0; i < playerName.length; i++) {
players.push({
name: playerName[i],
points: points[i],
assists: assists[i],
wins: wins[i]
});
}
// Procedure to get and display top players by a given stat
function getTopPlayersByStat(statName, count) {
// Sort players descending by selected stat

players.sort(function(a, b) {
return b[statName] - a[statName];
});
// Output the top players
for (var i = 0; (i < players.length); i++) {
if (i < count) {
console.log(players[i].name + " - " + statName + ": " + players[i][statName]);
}
}
}
// Call the procedure for each stat to display top 10 players
getTopPlayersByStat("points", 10);
getTopPlayersByStat("assists", 10);
getTopPlayersByStat("wins", 10);
// Event triggered when user selects a stat and clicks confirm
onEvent("confirmButton", "click", function() {
var selectedStat = getProperty("statSelector", "value");
setScreen("statScreen");

if (selectedStat == "Highest Career Points") {


setText("statText",
"LeBron James - points: 42036\n" +
"Kareem Abdul-Jabbar - points: 38387\n" +
"Karl Malone - points: 36928\n" +
"Kobe Bryant - points: 33643\n" +
"Michael Jordan - points: 32292\n" +
"Dirk Nowitzki - points: 31560\n" +
"Wilt Chamberlain - points: 31419\n" +
"Kevin Durant - points: 30571\n" +
"Shaquille O'Neal - points: 28596\n" +
"Carmelo Anthony - points: 28289"
);
showElement("statText");
} else if (selectedStat == "Highest Career Assists") {
setText("statText",
"John Stockton - assists: 15806\n" +
"Chris Paul - assists: 12453\n" +
"Jason Kidd - assists: 12091\n" +
"LeBron James - assists: 11546\n" +
"Steve Nash - assists: 10335\n" +
"Mark Jackson - assists: 10334\n" +
"Magic Johnson - assists: 10141\n" +
"Russell Westbrook - assists: 9892\n" +
"Oscar Robertson - assists: 9887\n" +
"Isiah Thomas - assists: 9061"
);
showElement("statText");
} else if (selectedStat == "Most Championship Wins") {
setText("statText",
"Bill Russell - wins: 11\n" +
"Sam Jones - wins: 10\n" +
"John Havlicek - wins: 8\n" +
"K.C. Jones - wins: 8\n" +
"Tom Heinsohn - wins: 8\n" +
"Tom Sanders - wins: 8\n" +
"Robert Horry - wins: 7\n" +
"Frank Ramsey - wins: 7\n" +
"Jim Loscutoff - wins: 7\n" +
"Bob Cousy - wins: 6"
);
showElement("statText");
} else {
setScreen("HomeScreen");
}
});
// Event triggered when user clicks the home button
onEvent("homeButton", "click", function() {
setScreen("HomeScreen");
});

You might also like