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

submit for application #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
# WEB102 Prework - *Name of App Here*
# WEB102 Prework - *game stats*

Submitted by: **Your Name Here**
Submitted by: **Robin Jiang**

**Name of your app** is a website for the company Sea Monster Crowdfunding that displays information about the games they have funded.
**game stats** 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!

* [x] List anything else that you can get done to improve the app functionality!
Added a cursor pointer in css for buttons.
## 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='/assets/Peek 2023-11-22 13-20.gif' title='Video Walkthrough' width='' alt='Video Walkthrough' />

<!-- Replace this with whatever GIF tool you used! -->
GIF created with ...
<!-- Recommended tools:
[Kap](https://getkap.co/) for macOS
[ScreenToGif](https://www.screentogif.com/) for Windows
[peek](https://github.com/phw/peek) for Linux. -->
[peek](https://github.com/phw/peek) for Linux.

## Notes

Describe any challenges encountered while building the app.

## License

Copyright [yyyy] [name of copyright owner]
Copyright [2023] [codepath]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Binary file added assets/Peek 2023-11-22 13-20.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 58 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,31 @@ const gamesContainer = document.getElementById("games-container");
function addGamesToPage(games) {

// loop over each item in the data


for (let i=0; i<games.length;i++) {
const game = games[i];
// create a new div element, which will become the game card


const gameCardDiv = document.createElement("div");
// add the class game-card to the list


gameCardDiv.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 ("/>")


gameCardDiv.innerHTML = `
<img src="${game.img}" alt="${game.name}" class="game-img" />
<h3>${game.name}</h3>
<p>Description: ${game.description}</p>
<p>Pledged: $${game.pledged}</p>
<p>Goal: $${game.goal}</p>
`;
// append the game to the games-container

document.getElementById("games-container").appendChild(gameCardDiv);
}
}

// call the function we just defined using the correct variable
// later, we'll call this function using a different list of games
addGamesToPage(GAMES_JSON);


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

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

const totalBackers = GAMES_JSON.reduce((sum, game) => sum + game.backers, 0);

// set the inner HTML using a template literal and toLocaleString to get a number with commas

contributionsCard.innerHTML = `${totalBackers.toLocaleString("en-US")}`;

// 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((sum, game) => sum + game.pledged, 0);
// set inner HTML using template literal

raisedCard.innerHTML = `$${totalRaised.toLocaleString("en-US")}`;

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

const totalGames = GAMES_JSON.length;
gamesCard.innerHTML = `${totalGames}`;

/*************************************************************************************
* Challenge 5: Add functions to filter the funded and unfunded games
Expand All @@ -83,33 +89,33 @@ const gamesCard = document.getElementById("num-games");
*/

// show only games that do not yet have enough funding
function filterUnfundedOnly() {
function filterUnfundedOnly(games) {
deleteChildElements(gamesContainer);

// use filter() to get a list of games that have not yet met their goal

const unfundedGames = games.filter(game => game.pledged < game.goal);

// use the function we previously created to add the unfunded games to the DOM

return addGamesToPage(unfundedGames);
}

// show only games that are fully funded
function filterFundedOnly() {
function filterFundedOnly(games) {
deleteChildElements(gamesContainer);

// use filter() to get a list of games that have met or exceeded their goal

const fundedGames = games.filter(game => game.pledged >= game.goal);

// use the function we previously created to add unfunded games to the DOM

return addGamesToPage(fundedGames);
}

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

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

return addGamesToPage(games);
}

// select each button in the "Our Games" section
Expand All @@ -118,7 +124,17 @@ 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', function () {
filterUnfundedOnly(GAMES_JSON);
});

fundedBtn.addEventListener('click', function () {
filterFundedOnly(GAMES_JSON);
});

allBtn.addEventListener('click', function () {
showAllGames(GAMES_JSON);
});

/*************************************************************************************
* Challenge 6: Add more information at the top of the page about the company.
Expand All @@ -129,13 +145,21 @@ const allBtn = document.getElementById("all-btn");
const descriptionContainer = document.getElementById("description-container");

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

const unfundedGamesArray = GAMES_JSON.filter(game => game.pledged < game.goal);
const unfundedCount = unfundedGamesArray.length;
const unfundedRaised = unfundedGamesArray.reduce((sum, game) => sum + game.pledged, 0);

// create a string that explains the number of unfunded games using the ternary operator

const unfundedString = unfundedCount > 0 ?
`A total of $${totalRaised.toLocaleString("en-US")} has been raised for
${totalGames} games. Currently, ${unfundedCount} game${unfundedCount > 1 ? "s" : ""}
remain unfunded. We need your help to fund these amazing games!`
: "All games are funded."

// create a new DOM element containing the template string and append it to the description container

const descriptionElement = document.createElement("p")
descriptionElement.innerHTML = unfundedString;
descriptionContainer.appendChild(descriptionElement);
/************************************************************************************
* Challenge 7: Select & display the top 2 games
* Skills used: spread operator, destructuring, template literals, sort
Expand All @@ -149,7 +173,14 @@ const sortedGames = GAMES_JSON.sort( (item1, item2) => {
});

// use destructuring and the spread operator to grab the first and second games
let [topFundedGame, secondTopFundedGame, ...remainingGames] = 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
const firstElement = document.createElement("p")
firstElement.innerHTML = topFundedGame.name;
firstGameContainer.appendChild(firstElement);

// do the same for the runner up item
const secondElement = document.createElement("p")
secondElement.innerHTML = secondTopFundedGame.name;
secondGameContainer.appendChild(secondElement);
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ body {

.stats-container {
display: flex;
align-items: center;
cursor: pointer;
box-shadow: 0 0 30px lightblue;
}

.stats-card {
Expand Down Expand Up @@ -72,4 +75,8 @@ button {
padding: 1%;
margin: 1%;
border-radius: 7px;
}

button:hover {
cursor: pointer;
}