From 412c7dc9683fc877f1d3818832fb7e0634834d25 Mon Sep 17 00:00:00 2001 From: eng-nur-sheekh-maxamed Date: Tue, 3 Jun 2025 09:11:56 -0700 Subject: [PATCH] Completed Week 6 assignment tasks eng Nur Sheikh --- array_challenges.js | 14 +++++-- dom_challenges.js | 98 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 96 insertions(+), 16 deletions(-) diff --git a/array_challenges.js b/array_challenges.js index 3e3c564..6014586 100644 --- a/array_challenges.js +++ b/array_challenges.js @@ -3,7 +3,8 @@ The Dataset: Movie Mania -You are managing a database for a **movie rental platform** called **Movie Mania**. The dataset is an array of objects, where each object represents a movie with the following properties: +You are managing a database for a **movie rental platform** called **Movie Mania**. The dataset is an array of objects, + where each object represents a movie with the following properties: - `title` (string): The title of the movie. - `genre` (string): The genre of the movie (e.g., "Action", "Comedy", "Drama"). @@ -46,7 +47,12 @@ const movies = [ // ✍️ Solve it here ✍️ - + const movieTitlRatings = movies.map(movie => { + return `${movie.title} - Rating: ${movie.rating}/10`; +}); + +console.log(movieTitlRatings); + /* Task 2: Find Highly Rated Movies 🌟 (`.filter`) @@ -68,4 +74,6 @@ const movies = [ // ✍️ Solve it here ✍️ - \ No newline at end of file + const RatedMovies = movies.filter(movie => movie.rating >= 8.0); + +console.log(RatedMovies); diff --git a/dom_challenges.js b/dom_challenges.js index bb943d5..6ad886e 100644 --- a/dom_challenges.js +++ b/dom_challenges.js @@ -124,31 +124,103 @@ export const newsData = { export function displayArticles(category) { const newsContainer = document.querySelector('#news-container'); const articles = newsData[category]; - + + //
+ // + //
+ // 1. Clear previous content - + newsContainer.innerHTML = ''; // 2. Create container elements - + const featuredArticleContainer = document.createElement("div"); + featuredArticleContainer.className = "featured-article"; // 3. Create article element - + const featured = articles[0]; + + const articleEl = document.createElement("article"); + articleEl.className = "news-card featured"; // 4. Create and setup image - + const img = document.createElement("img"); + img.className = "news-image"; + img.src = featured.image; + img.alt = featured.title; // 5. Create content container - + const contentDiv = document.createElement("div"); + contentDiv.className = "news-content"; // 6. Create featured label - + const label = document.createElement("span"); + label.className = "featured-label"; + label.textContent = "Featured Story"; // 7. Create title - + const title = document.createElement("h2"); + title.className = "news-title"; + title.textContent = featured.title; // 8. Create date - + const date = document.createElement("div"); + date.className = "news-date"; + date.textContent = featured.date; // 9. Create excerpt - + const excerpt = document.createElement("p"); + excerpt.className = "news-excerpt"; + excerpt.textContent = featured.excerpt; // 10. Create tag - + const tag = document.createElement("span"); + tag.className = "tag"; + tag.textContent = featured.tag; // 11. Assemble the elements + contentDiv.append(label, title, date, excerpt, tag); + articleEl.append(img, contentDiv); + featuredArticleContainer.append(articleEl); + newsContainer.append(featuredArticleContainer); + + const newsGrid = document.createElement("div"); + newsGrid.className = "news-grid"; + + for (let i = 1; i < articles.length; i++) { + const article = articles[i]; + + const articleEl = document.createElement("article"); + articleEl.className = "news-card"; + + const img = document.createElement("img"); + img.className = "news-image"; + img.src = article.image; + img.alt = article.title; + + const contentDiv = document.createElement("div"); + contentDiv.className = "news-content"; + + const title = document.createElement("h2"); + title.className = "news-title"; + title.textContent = article.title; + + const date = document.createElement("div"); + date.className = "news-date"; + date.textContent = article.date; + + const excerpt = document.createElement("p"); + excerpt.className = "news-excerpt"; + excerpt.textContent = article.excerpt; + + const tag = document.createElement("span"); + tag.className = "tag"; + tag.textContent = article.tag; + + contentDiv.append(title, date, excerpt, tag); + articleEl.append(img, contentDiv); + newsGrid.append(articleEl); + } - - newsContainer.insertBefore(featuredArticle, newsContainer.firstChild); + newsContainer.append(newsGrid); }