Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CYF Glasgow | Iakub Dubachev | TV-show | Level 100 #20

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
scrip.js updated
  • Loading branch information
IakubDubachev committed Dec 29, 2024
commit ec6f905f73c8bbaa76c424295e2023441dc84696
54 changes: 51 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
//You can edit ALL of the code here
function setup() {
const allEpisodes = getAllEpisodes();
makePageForEpisodes(allEpisodes);
}

// Function to render all episodes on the page
function makePageForEpisodes(episodeList) {
const rootElem = document.getElementById("root");
rootElem.textContent = `Got ${episodeList.length} episode(s)`;
rootElem.innerHTML = ''; // Clear any existing content

const episodeCount = document.createElement('p');
episodeCount.textContent = `Got ${episodeList.length} episode(s)`;
rootElem.appendChild(episodeCount);

// Create a container for episodes
const episodeContainer = document.createElement('div');
episodeContainer.id = 'episode-container';
rootElem.appendChild(episodeContainer);

episodeList.forEach((episode) => {
const episodeCard = document.createElement('div');
episodeCard.className = 'episode-card';

// Episode Title with Episode Code
const episodeTitle = document.createElement('h3');
episodeTitle.textContent = `${formatEpisodeCode(episode.season, episode.number)} - ${episode.name}`;

// Episode Image
const episodeImage = document.createElement('img');
episodeImage.src = episode.image?.medium || 'placeholder.jpg';
episodeImage.alt = episode.name;

// Episode Summary
const episodeSummary = document.createElement('p');
episodeSummary.innerHTML = episode.summary || 'No summary available.';

// Link to TVMaze episode page
const episodeLink = document.createElement('a');
episodeLink.href = episode.url;
episodeLink.target = '_blank';
episodeLink.textContent = 'View on TVMaze';

// Append elements to the episode card
episodeCard.appendChild(episodeTitle);
episodeCard.appendChild(episodeImage);
episodeCard.appendChild(episodeSummary);
episodeCard.appendChild(episodeLink);

// Add episode card to container
episodeContainer.appendChild(episodeCard);
});
}

// Format the episode code (e.g., S02E07)
function formatEpisodeCode(season, number) {
return `S${String(season).padStart(2, '0')}E${String(number).padStart(2, '0')}`;
}

window.onload = setup;
// Run the setup when the page loads
window.onload = setup;