Task 21: Get Your Favorite Football Team Info with JavaScript + Axios!
Start with Affirmationβ
- "I am destined for greatness. Every step I take brings me closer to my goals. I embrace challenges, knowing they are stepping stones to success. My mind is focused, my heart is determined, and my actions are aligned with my dreams."
Daily Affirmations for Success
- β I am capable, confident, and unstoppable.
- β Success flows to me because I take consistent action.
- β I attract opportunities that align with my purpose.
- β My hard work and persistence create abundance.
- β I am always learning, growing, and evolving.
- β I believe in my potential and trust my journey.
- β I turn setbacks into comebacks with resilience.
- β I am grateful for every success, big and small.
Success Reflectionβ
"Every effort I made today has planted seeds for my future success. I release any doubts and trust the process. My dreams are possible, and I am getting closer every day. I am grateful, I am strong, and I am ready for more!"
πͺ Repeat daily, feel the power, and watch your success unfold!
Task Answer - Video Linkβ
πΉ If you donβt understand the task, watch the video above for the answer.
Taskβ
In this task video, you'll learn how to use JavaScript and Axios to fetch real-time information about your favorite football team using a public API. Whether youβre building a sports stats app or just exploring API requests, this beginner-friendly tutorial walks you through every stepβfrom setting up Axios to displaying team data dynamically.
What You'll Learn:
- β How to use Axios for HTTP requests
- β How to fetch football team info via API
- β How to handle JSON responses in JavaScript
- β Real-world API project for JS beginners
** Step 1: Create HTML Structureβ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>β½ Football Team Info</title>
</head>
<body>
<h1>β½ Team Info Finder</h1>
<input type="text" id="teamInput" placeholder="Enter Team Name..." />
<button id="getTeam">Get Info</button>
<div id="result"></div>
<!-- Axios CDN -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="script.js"></script>
</body>
</html>
Step 2: JavaScript Logic (script.js)β
const getBtn = document.getElementById("getTeam");
const result = document.getElementById("result");
getBtn.addEventListener("click", () => {
const team = document.getElementById("teamInput").value.trim();
if (!team) {
result.innerHTML = "β Please enter a team name.";
return;
}
axios.get(`https://www.thesportsdb.com/api/v1/json/3/searchteams.php?t=${team}`)
.then(response => {
const teamInfo = response.data.teams ? response.data.teams[0] : null;
if (!teamInfo) {
result.innerHTML = "β οΈ Team not found. Try another name!";
return;
}
result.innerHTML = `
<h2>${teamInfo.strTeam}</h2>
<p>ποΈ Stadium: ${teamInfo.strStadium}</p>
<p>π Location: ${teamInfo.strStadiumLocation}</p>
<p>π
Formed Year: ${teamInfo.intFormedYear}</p>
<p>π Description: ${teamInfo.strDescriptionEN.slice(0, 200)}...</p>
<img src="${teamInfo.strTeamBadge}" alt="${teamInfo.strTeam} Badge" width="150" />
`;
})
.catch(err => {
console.error(err);
result.innerHTML = "β Something went wrong! Try again.";
});
});