Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# WEB102 Prework - *Name of App Here*
# WEB102 Prework - *Sea Monster Crowdfunding*

Submitted by: **Your Name Here**
Submitted by: **Sajid Amin**

**Name of your app** is a website for the company Sea Monster Crowdfunding that displays information about the games they have funded.
**GameLabz** 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: **3** 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!
* [-] List anything else that you can get done to improve the app functionality!

## Video Walkthrough

Here's a walkthrough of implemented features:

<img src='http://i.imgur.com/link/to/your/gif/file.gif' title='Video Walkthrough' width='' alt='Video Walkthrough' />
<img src='https://i.imgur.com/wcZ7is2.gif' title='Video Walkthrough' width='' alt='Video Walkthrough' />

<!-- Replace this with whatever GIF tool you used! -->
GIF created with ...
GIF created with Adobe reader
<!-- Recommended tools:
[Kap](https://getkap.co/) for macOS
[ScreenToGif](https://www.screentogif.com/) for Windows
Expand All @@ -38,7 +38,7 @@ Describe any challenges encountered while building the app.

## License

Copyright [yyyy] [name of copyright owner]
Copyright 2025 Sajid Amin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
69 changes: 52 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@ function deleteChildElements(parent) {
// grab the element with the id games-container
const gamesContainer = document.getElementById("games-container");


// create a function that adds all data from the games array to the page
function addGamesToPage(games) {

// loop over each item in the data

for (let game of games) {
const gameCard = document.createElement("div");
gameCard.classList.add("game-card");
gameCard.innerHTML = `
<img class="game-img" src="${game.img}" alt="Game image" />
<h3>${game.name}</h3>
<p>${game.description}</p>
<p><strong>Backers:</strong> ${game.backers}</p>
`;

gamesContainer.appendChild(gameCard);

// create a new div element, which will become the game card

Expand All @@ -46,8 +57,10 @@ function addGamesToPage(games) {
// append the game to the games-container

}

}
// 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


Expand All @@ -61,20 +74,24 @@ function addGamesToPage(games) {
const contributionsCard = document.getElementById("num-contributions");

// use reduce() to count the number of total contributions by summing the backers

const totalContributions = GAMES_JSON.reduce((acc, game) => acc + game.backers, 0);

// set the inner HTML using a template literal and toLocaleString to get a number with commas
contributionsCard.innerHTML = totalContributions.toLocaleString();




// grab the amount raised card, then use reduce() to find the total amount raised
const raisedCard = document.getElementById("total-raised");

const totalRaised = GAMES_JSON.reduce((acc, game) => acc + game.pledged, 0);
// set inner HTML using template literal
raisedCard.innerHTML = `$${totalRaised.toLocaleString()}`;


// grab number of games card and set its inner HTML
const gamesCard = document.getElementById("num-games");

gamesCard.innerHTML = GAMES_JSON.length;

/*************************************************************************************
* Challenge 5: Add functions to filter the funded and unfunded games
Expand All @@ -87,29 +104,30 @@ 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);
console.log("Unfunded:", unfundedGames.length);
}

// show only games that are fully funded
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

addGamesToPage(fundedGames);
console.log("Funded:", fundedGames.length);
}

// show all games
function showAllGames() {
deleteChildElements(gamesContainer);

// add all games from the JSON data to the DOM

addGamesToPage(GAMES_JSON);
}

// select each button in the "Our Games" section
Expand All @@ -118,23 +136,33 @@ 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);

/*************************************************************************************
* Challenge 6: Add more information at the top of the page about the company.
* Skills used: template literals, ternary operator
*/


// grab the description container
const descriptionContainer = document.getElementById("description-container");

// use filter or reduce to count the number of unfunded games

const numUnfunded = GAMES_JSON.reduce((acc, game) => {
return game.pledged < game.goal ? acc + 1 : acc;
}, 0);

// create a string that explains the number of unfunded games using the ternary operator
const displayStr = `A total of $${totalRaised.toLocaleString()} has been raised for ${GAMES_JSON.length} games. ${numUnfunded} ${numUnfunded === 1 ? 'game remains' : 'games remain'} unfunded. We need your help to fund these amazing games!`;


// create a new DOM element containing the template string and append it to the description container
const paragraph = document.createElement("p");
paragraph.textContent = displayStr;
descriptionContainer.appendChild(paragraph);


/************************************************************************************
* Challenge 7: Select & display the top 2 games
Expand All @@ -144,12 +172,19 @@ const descriptionContainer = document.getElementById("description-container");
const firstGameContainer = document.getElementById("first-game");
const secondGameContainer = document.getElementById("second-game");

const sortedGames = GAMES_JSON.sort( (item1, item2) => {
return item2.pledged - item1.pledged;
});
const sortedGames = GAMES_JSON.sort((a, b) => b.pledged - a.pledged);
const [firstGame, secondGame, ...rest] = sortedGames;

// use destructuring and the spread operator to grab the first and second games

// 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
// do the same for the runner up item

const topGameElement = document.createElement("p");
topGameElement.textContent = firstGame.name;
firstGameContainer.appendChild(topGameElement);

const runnerUpElement = document.createElement("p");
runnerUpElement.textContent = secondGame.name;
secondGameContainer.appendChild(runnerUpElement);
10 changes: 9 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ body {

.stats-container {
display: flex;
}
align-items: center;
justify-content: center;
}


.stats-container:hover {
cursor: pointer;
box-shadow: 0 0 30px lightblue;
}

.stats-card {
background-color: #a8b0bc;
Expand Down