%%js

// app.js
const express = require('express');
const app = express();
const port = 3000; // You can choose any available port

// Generate random NBA player statistics
function generateNBAStats(playerName) {
  const points = Math.floor(Math.random() * 30) + 1; // Random points between 1 and 30
  const rebounds = Math.floor(Math.random() * 15) + 1; // Random rebounds between 1 and 15
  const assists = Math.floor(Math.random() * 10) + 1; // Random assists between 1 and 10

  return {
    playerName,
    points,
    rebounds,
    assists,
  };
}

// Define an API endpoint to get NBA player statistics
app.get('/api/nba-stats/:playerName', (req, res) => {
  const playerName = req.params.playerName;
  const nbaStats = generateNBAStats(playerName);
  res.json(nbaStats);
});

app.listen(port, () => {
  console.log(`API server is running on http://localhost:${port}`);
});
<IPython.core.display.Javascript object>
%%HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>NBA Player Stats</title>
</head>
<body>
    <h1>NBA Player Statistics</h1>
    <label for="playerName">Enter NBA Player Name:</label>
    <input type="text" id="playerName" placeholder="e.g., LeBron James">
    <button onclick="fetchNBAStats()">Fetch Stats</button>

    <div id="stats-container">
        <!-- NBA player stats will be displayed here -->
    </div>

    <script>
        async function fetchNBAStats() {
            const playerName = document.getElementById('playerName').value;
            const apiUrl = `http://localhost:3000/api/nba-stats/${encodeURIComponent(playerName)}`;

            try {
                const response = await fetch(apiUrl);

                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }

                const data = await response.json();

                // Display the NBA player stats on the webpage
                const statsContainer = document.getElementById('stats-container');
                statsContainer.innerHTML = `
                    <h2>${data.playerName} Statistics:</h2>
                    <p>Points: ${data.points}</p>
                    <p>Rebounds: ${data.rebounds}</p>
                    <p>Assists: ${data.assists}</p>
                `;
            } catch (error) {
                console.error('Error:', error);
            }
        }
    </script>
</body>
</html>

<!DOCTYPE html>

NBA Player Stats

NBA Player Statistics