generated from EnclaveGames/Enclave-Phaser-Template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
trade_analyzer.html
131 lines (122 loc) · 5.24 KB
/
trade_analyzer.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>NBA Trade Analyzer</title>
<style>
/* Styling for the body */
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
/* Styling for the heading */
h1 {
color: #333;
}
/* Styling for select and button elements */
select, button {
padding: 10px;
margin: 5px;
border-radius: 5px;
border: 1px solid #ddd;
background-color: #fff;
}
/* Styling for the button */
button {
cursor: pointer;
background-color: #007BFF;
color: white;
border: none;
}
/* Styling for the button on hover */
button:hover {
background-color: #0056b3;
}
/* Styling for paragraph elements */
p {
color: #444;
font-size: 16px;
margin: 10px 0;
}
/* Styling for the container */
.container {
box-shadow: 0 0 15px rgba(0,0,0,0.1);
padding: 20px;
border-radius: 8px;
background: white;
width: 300px;
}
</style>
<script>
// Hardcoded player data
const players = [
{ id: 1, name: 'LeBron James', stats: { points: 25, assists: 7, rebounds: 7 }},
{ id: 2, name: 'Kevin Durant', stats: { points: 27, assists: 5, rebounds: 7 }},
{ id: 3, name: 'Stephen Curry', stats: { points: 30, assists: 6, rebounds: 5 }},
{ id: 4, name: 'Giannis Antetokounmpo', stats: { points: 29, assists: 5, rebounds: 12 }},
{ id: 5, name: 'James Harden', stats: { points: 26, assists: 11, rebounds: 8 }},
{ id: 6, name: 'Kawhi Leonard', stats: { points: 25, assists: 4, rebounds: 6 }},
{ id: 7, name: 'Anthony Davis', stats: { points: 22, assists: 3, rebounds: 10 }},
{ id: 8, name: 'Luka Doncic', stats: { points: 28, assists: 8, rebounds: 9 }},
{ id: 9, name: 'Joel Embiid', stats: { points: 27, assists: 3, rebounds: 11 }},
{ id: 10, name: 'Nikola Jokic', stats: { points: 25, assists: 7, rebounds: 11 }},
{ id: 11, name: 'Damian Lillard', stats: { points: 26, assists: 7, rebounds: 4 }},
{ id: 12, name: 'Jimmy Butler', stats: { points: 21, assists: 6, rebounds: 6 }},
{ id: 13, name: 'Paul George', stats: { points: 23, assists: 4, rebounds: 6 }},
{ id: 14, name: 'Russell Westbrook', stats: { points: 22, assists: 10, rebounds: 11 }},
{ id: 15, name: 'Kyrie Irving', stats: { points: 27, assists: 6, rebounds: 4 }}
];
// Event listener for when the DOM content is loaded
document.addEventListener('DOMContentLoaded', function() {
populatePlayers(); // Call the function to populate players in dropdowns
});
// Function to populate players in dropdown menus
function populatePlayers() {
const playerSelect1 = document.getElementById('player1');
const playerSelect2 = document.getElementById('player2');
// Populate the dropdown menus with players
players.forEach(player => {
const option1 = document.createElement('option'); // Create option element for player 1 dropdown
const option2 = document.createElement('option'); // Create option element for player 2 dropdown
option1.value = option2.value = player.id; // Set the value of options to player ID
option1.textContent = option2.textContent = player.name; // Set the text content of options to player name
playerSelect1.appendChild(option1); // Append option to player 1 dropdown
playerSelect2.appendChild(option2); // Append option to player 2 dropdown
});
}
// Function to analyze the trade
async function analyzeTrade() {
const player1 = document.getElementById('player1').value; // Get the selected value of player 1 dropdown
const player2 = document.getElementById('player2').value; // Get the selected value of player 2 dropdown
// Extract player data
const playerData1 = players.find(p => p.id == player1); // Find player 1 data from the players array
const playerData2 = players.find(p => p.id == player2); // Find player 2 data from the players array
// Simulate a trade analysis
const score1 = playerData1.stats.points + playerData1.stats.assists * 2 + playerData1.stats.rebounds * 1.5; // Calculate score for player 1
const score2 = playerData2.stats.points + playerData2.stats.assists * 2 + playerData2.stats.rebounds * 1.5; // Calculate score for player 2
// Displaying the results
document.getElementById('score1').textContent = `Score for ${playerData1.name}: ${score1}`; // Display score for player 1
document.getElementById('score2').textContent = `Score for ${playerData2.name}: ${score2}`; // Display score for player 2
document.getElementById('recommendation').textContent = `Better Trade: ${score1 > score2 ? playerData1.name : playerData2.name}`; // Display recommendation based on scores
}
</script>
</head>
<body>
<div class="container">
<h1>NBA Trade Analyzer</h1>
<!-- Player Selection Dropdowns and Analyze Trade Button -->
<select id="player1"></select>
<select id="player2"></select>
<button onclick="analyzeTrade()">Analyze Trade</button>
<!-- Results Display -->
<p id="score1"></p>
<p id="score2"></p>
<p id="recommendation"></p>
</div>
</body>
</html>