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

Finished Project #57

Open
wants to merge 3 commits 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
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# WEB102 Prework - *Name of App Here*
# WEB102 Prework - Sea Monster

Submitted by: **Your Name Here**
Submitted by: Saartaj Alam
Sea Monster Crowdfunding is a website for the company Sea Monster Crowdfunding that displays information about the games they have funded.

**Name of your app** 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: 20 hours spent in total

## Required Features

Expand All @@ -23,18 +22,18 @@ The following **optional** features are implemented:

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://imgur.com/A5LkC8l' title='Video Walkthrough' width='' alt='Video Walkthrough' />

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

## Notes

Describe any challenges encountered while building the app.
Understanding the way functions use callback functions as their argumnents took some time for me to wrap my head around.

## License

Expand Down
79 changes: 54 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,35 @@ const gamesContainer = document.getElementById("games-container");
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

let div = document.createElement("div");

// add the class game-card to the list

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


div.innerHTML = `
<img class="game-img" src="${games[i].img}"></img>
<h1>${games[i].name}</h1>
<h2>${games[i].description}</h2>
<h3>Backers: ${games[i].backers}</h3>
`

// append the game to the games-container

gamesContainer.append(div);
}
}


// 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);

/*************************************************************************************
* Challenge 4: Create the summary statistics at the top of the page displaying the
Expand All @@ -61,20 +69,23 @@ 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) => {
return acc + game.backers;
}, 0)
// set the inner HTML using a template literal and toLocaleString to get a number with commas

contributionsCard.innerHTML = `<p>${totalContributions.toLocaleString("en-us")}</p>`;

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

raisedCard.innerHTML = `<p>${totalRaised.toLocaleString("en-us")}</p>`

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

gamesCard.innerHTML = `<p>${GAMES_JSON.length}</p>`

/*************************************************************************************
* Challenge 5: Add functions to filter the funded and unfunded games
Expand All @@ -87,29 +98,33 @@ function filterUnfundedOnly() {
deleteChildElements(gamesContainer);

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

let unfundedGames = GAMES_JSON.filter((game) => {
return game.pledged < game.goal;
});

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

addGamesToPage(unfundedGames);
}

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

let fundedGames = GAMES_JSON.filter((game) => {
return game.pledged >= game.goal;
});

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

addGamesToPage(fundedGames)
}

// 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,7 +133,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);

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

// use filter or reduce to count the number of unfunded games
const unfunded = GAMES_JSON.filter((game) =>{
return game.pledged < game.goal
}).length;


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


let toAdd = unfunded > 1 ? `Currently, ${unfunded} games remain unfunded.` : "Currently, 1 game remains unfunded."
let displayStr = `A total of $${totalRaised.toLocaleString()} has been raised for ${GAMES_JSON.length} games. ` + toAdd + " 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

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

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

const first = sortedGames[0];
const second = sortedGames[1];
// 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
let div1 = document.createElement("div")
div1.innerHTML = first.name;
firstGameContainer.append(div1);

// do the same for the runner up item
let div2 = document.createElement("div")
div2.innerHTML = second.name;
secondGameContainer.append(div2);
8 changes: 7 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ body {

.stats-container {
display: flex;
cursor: pointer;
}

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

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