diff --git a/README.md b/README.md index a12177342..eee2538ea 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,29 @@ -# WEB102 Prework - *Name of App Here* +# WEB102 Prework - *Sea Monster Game* -Submitted by: **Your Name Here** +Submitted by: **Ida Touray** -**Name of your app** is a website for the company Sea Monster Crowdfunding that displays information about the games they have funded. +Sea Monster is a website for the company Sea Monster Crowdfunding that displays information about the games they have funded. -Time spent: **X** hours spent in total +Time spent: 6 hours spent in total ## Required Features The following **required** functionality is completed: -* [ ] The introduction section explains the background of the company and how many games remain unfunded. -* [ ] The Stats section includes information about the total contributions and dollars raised as well as the top two most funded games. -* [ ] The Our Games section initially displays all games funded by Sea Monster Crowdfunding -* [ ] The Our Games section has three buttons that allow the user to display only unfunded games, only funded games, or all games. +* [x] The introduction section explains the background of the company and how many games remain unfunded. +* [x] The Stats section includes information about the total contributions and dollars raised as well as the top two most funded games. +* [x] The Our Games section initially displays all games funded by Sea Monster Crowdfunding +* [x] The Our Games section has three buttons that allow the user to display only unfunded games, only funded games, or all games. The following **optional** features are implemented: -* [ ] List anything else that you can get done to improve the app functionality! +* [x] List anything else that you can get done to improve the app functionality! ## Video Walkthrough Here's a walkthrough of implemented features: -Video Walkthrough +Video Walkthrough GIF created with ... @@ -32,13 +32,14 @@ GIF created with ... [ScreenToGif](https://www.screentogif.com/) for Windows [peek](https://github.com/phw/peek) for Linux. --> -## Notes +## Notes -Describe any challenges encountered while building the app. +- I Got practice using filters,functionns, loops and DOM manipulation. +- One of the challenges I faced was displaying the website live as I was editing the script page. ## License - Copyright [yyyy] [name of copyright owner] + Copyright [2026] [Ida Touray] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/index.js b/index.js index 86fe7d438..14a9d6791 100644 --- a/index.js +++ b/index.js @@ -30,24 +30,36 @@ function addGamesToPage(games) { // loop over each item in the data + for (let i = 0; i < games.length; i++) { // create a new div element, which will become the game card + const gameCard = document.createElement("div"); // add the class game-card to the list + gameCard.classList.add("game-card"); // set the inner HTML using a template literal to display some info // about each game // TIP: if your images are not displaying, make sure there is space // between the end of the src attribute and the end of the tag ("/>") + gameCard.innerHTML = ` + +

${games[i].name}

+

${games[i].description}

+

Backers: ${games[i].backers}

+ `; // append the game to the games-container + gamesContainer.appendChild(gameCard); + } } // call the function we just defined using the correct variable +addGamesToPage(GAMES_JSON); // later, we'll call this function using a different list of games @@ -62,8 +74,12 @@ const contributionsCard = document.getElementById("num-contributions"); // use reduce() to count the number of total contributions by summing the backers +const count = GAMES_JSON.reduce( (acc, game) => { + return acc + game.backers; +}, 0); // set the inner HTML using a template literal and toLocaleString to get a number with commas +contributionsCard.innerHTML = `${count.toLocaleString('en-US')}`; // grab the amount raised card, then use reduce() to find the total amount raised @@ -71,10 +87,14 @@ const raisedCard = document.getElementById("total-raised"); // set inner HTML using template literal +raisedCard.innerHTML = `$${GAMES_JSON.reduce( (acc, game) => { + return acc + game.pledged; +}, 0).toLocaleString('en-US')}`; // grab number of games card and set its inner HTML const gamesCard = document.getElementById("num-games"); +gamesCard.innerHTML = `${GAMES_JSON.length.toLocaleString('en-US')}`; /************************************************************************************* * Challenge 5: Add functions to filter the funded and unfunded games @@ -87,9 +107,11 @@ function filterUnfundedOnly() { deleteChildElements(gamesContainer); // use filter() to get a list of games that have not yet met their goal + const unfundedGames = GAMES_JSON.filter(game => game.pledged < game.goal); // use the function we previously created to add the unfunded games to the DOM + addGamesToPage(unfundedGames); } @@ -98,10 +120,11 @@ function filterFundedOnly() { deleteChildElements(gamesContainer); // use filter() to get a list of games that have met or exceeded their goal - + const fundedGames = GAMES_JSON.filter(game => game.pledged >= game.goal); // use the function we previously created to add unfunded games to the DOM - + // use the function we previously created to add the funded games to the DOM + addGamesToPage(fundedGames); } // show all games @@ -109,6 +132,7 @@ function showAllGames() { deleteChildElements(gamesContainer); // add all games from the JSON data to the DOM + addGamesToPage(GAMES_JSON); } @@ -118,6 +142,9 @@ const fundedBtn = document.getElementById("funded-btn"); const allBtn = document.getElementById("all-btn"); // add event listeners with the correct functions to each button +unfundedBtn.addEventListener("click", filterUnfundedOnly); +fundedBtn.addEventListener("click", filterFundedOnly); +allBtn.addEventListener("click", showAllGames); /************************************************************************************* @@ -130,11 +157,16 @@ const descriptionContainer = document.getElementById("description-container"); // use filter or reduce to count the number of unfunded games +const unfundedCount = GAMES_JSON.filter(game => game.pledged < game.goal).length; // create a string that explains the number of unfunded games using the ternary operator +const descriptionText = `We have ${unfundedCount} unfunded games that need your support!`; // create a new DOM element containing the template string and append it to the description container +const descriptionElement = document.createElement("p"); +descriptionElement.innerHTML = descriptionText; +descriptionContainer.appendChild(descriptionElement); /************************************************************************************ * Challenge 7: Select & display the top 2 games @@ -149,7 +181,16 @@ const sortedGames = GAMES_JSON.sort( (item1, item2) => { }); // use destructuring and the spread operator to grab the first and second games +const [firstGame, secondGame] = sortedGames; // create a new element to hold the name of the top pledge game, then append it to the correct element -// do the same for the runner up item \ No newline at end of file +// do the same for the runner up item +const firstGameElement = document.createElement("p"); +firstGameElement.innerHTML = firstGame.name; +firstGameContainer.appendChild(firstGameElement); + +// do the same for the runner up item +const secondGameElement = document.createElement("p"); +secondGameElement.innerHTML = secondGame.name; +secondGameContainer.appendChild(secondGameElement); \ No newline at end of file diff --git a/style.css b/style.css index 11303c2a7..57f0a6d8e 100644 --- a/style.css +++ b/style.css @@ -7,7 +7,7 @@ body { #tentacles { width: 50px; -} +} .header { display: flex; @@ -19,8 +19,10 @@ body { margin-top: -10px; } -.stats-container { +.stats-container:hover { display: flex; + align-items: center; + box-shadow: 0 0 30px lightblue; } .stats-card {