Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                  <div class="demo-brand">DEMO</div>
    <main>

        <section class="purpose">
            <article>
                <h2>What's the matter?</h2>
                <p>
                    It is a matter of consenting to the
                    pollution caused by solid waste and the inefficient
                    and the inefficient use of plastic in disposal.

                    The plastic we use can be put to more efficient uses, and one of them is
                    creating eco-friendly plastic bricks to build houses for the homeless.
                    houses for the homeless.

                    Social media can change society,
                    because let's face it, young people right now, many of them are very young.
                    are influenced by social networks or directly by what they find relevant and they pay more attention
                    to it.
                    They are influenced by social networks or directly by what seems relevant to them and they pay more
                    attention to it than to something that appears in a newspaper.

                    With this we can know that a simple post on the internet can change things, so why not use it in the
                    right way?

                    That's why I have created this application, to simulate a situation
                    situation where you start recycling and you have the possibility to upload a post related to the
                    related to the consent of contamination, which can make more people recycling the same
                    that there are more people recycling the same as you, and you can recycle more per day,
                    because there are more people recycling the same as you and donating.


                </p>
            </article>
        </section>

        <header>
            <h1 class="header-title">Statistics</h1>
            <section class="co2-emission">
                <article class="co2-emission-info">
                    <h2>CO2 EMISSION</h2>
                    <span id="emission-counter">
                        780 grams
                    </span>
                </article>
            </section>
            <section class="pollution-consent">
                <article class="pollution-consent-info">
                    <h2>Consented persons</h2>
                    <span id="consented-counter">
                        500
                    </span>
                </article>
            </section>
            <section class="houses-built">
                <article class="houses-built-info">
                    <h2>houses built</h2>
                    <span id="built-counter">
                        850
                    </span>
                </article>
            </section>
 
        </header>
        <section class="bottles-recycled">
            <article class="recycled-info">
                <h2>
                    Recycled bottles - 2,5 m grams per house
                </h2>
                <h3>Bottles recycled x People consented</h3>
                <span id="recycled-counter">
                    100 x 500
                </span>
            </article>
        </section>
        <section class="actions">
            <article class="buttons">
                <button class="recycle" id="recycle_btn">Recycle</button>
                <button class="post" id="post_btn">Make a post!</button>
            </article>
        </section>

    </main>

              
            
!

CSS

              
                body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

main {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
}

.header-title {
    flex: 1 1 100%;
    text-align: center;
    margin-bottom: 10px;
}

.co2-emission,
.pollution-consent,
.houses-built {
    flex-basis: 100%;
    margin-bottom: 10px;
}

.co2-emission-info,
.pollution-consent-info,
.houses-built-info {
    padding: 20px;
    background-color: #f5f5f5;
    border-radius: 5px;
    text-align: center;
}

.bottles-recycled,
.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-bottom: 20px;
}

.recycled-info {
    flex-basis: 100%;
}

.buttons {
    flex-basis: 100%;
}

button {
    display: block;
    width: 100%;
    padding: 10px;
    font-size: 16px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

button:hover {
    background-color: #45a049;
}

.demo-brand {
    position: fixed;
    top: 10px;
    left: 10px;
    padding: 10px;
    background-color: #000;
    color: #fff;
    font-weight: bold;
}

@media screen and (min-width: 600px) {
    header {
        justify-content: space-between;
    }

    .header-title {
        flex: 0 0 100%;
        margin-bottom: 0;
    }

    .co2-emission,
    .pollution-consent,
    .houses-built {
        flex-basis: calc(33.33% - 10px);
        margin-bottom: 10px;
    }

    .recycled-info {
        flex-basis: calc(50% - 10px);
    }
}
              
            
!

JS

              
                /*
  Author: Char
  This code was made for reusability and readability purposes.
*/

// Functions

// Renders the data on the webpage
function render() {
  const {
    emission,
    consented,
    houses,
    recycled,
    plasticGRecycled,
    homelessSaved
  } = actualData;

  saved();

  emissionCounter.innerText = `${emission / 1000000} tons`; // Displays the emission value in tons
  consentedCounter.innerText = consented; // Displays the consented value
  housesCounter.innerText = `${houses} (${homelessSaved} people in total)`; // Displays the number of houses and the total number of people saved
  recycledBottlesCounter.innerText = `${recycled} (${plasticGRecycled}g) x ${consented}`; // Displays the number of recycled bottles, the total weight of recycled plastic, and the consented value

  return actualData;
}

// Checks if a certain number of people have been saved and displays an alert message if true
function saved() {
  let demo_limit = 10;
  if (actualData.homelessSaved >= demo_limit) {
    alert(`You gave a home to ${demo_limit} people`);
    alert("I think you should use this solution in more places, and with a different social method.");
    alert("Thanks for the help! - Char and everyone.");
    setDefault();
  }
}

// Calculates the number of houses that can be built based on the amount of recycled plastic
function calcHouses() {
  let bricks = Math.floor(actualData.recycledTotal / plasticPerBrick);
  let houses = Math.floor(bricks / bricksPerHouse);

  return houses;
}

// Updates the data when the recycle button is clicked
function recycle() {
  actualData.recycled += 1;
  actualData.recycledTotal = actualData.recycled * actualData.consented;
  actualData.plasticGRecycled = actualData.recycledTotal * gPerBottle;
  actualData.emission -= emissionPerBottle * actualData.recycledTotal;
  actualData.emission += emissionPerBottle * actualData.recycledTotal + 50;
  actualData.houses = calcHouses();
  actualData.homelessSaved = Math.floor(actualData.houses * peoplePerHouse);
}

// Simulates a social media post and updates the data accordingly
function doPost() {
  let follows = Math.floor(Math.random() * followersRandomLimit);
  follows = (follows == 0) ? 1 : follows;
  console.log(`+Follows ${follows}`);
  actualData.consented += follows;
}

// Retrieves data from the local storage
function getData() {
  return JSON.parse(localStorage.getItem('bottles'));
}

// Updates the data in the local storage
function updateData() {
  const stringifyedObject = JSON.stringify(actualData);
  localStorage.setItem('bottles', stringifyedObject);
}

// Sets the default values for the data
function setDefault() {
  actualData = defaultSchema;
  const stringifyedObject = JSON.stringify(defaultSchema);
  localStorage.setItem('bottles', stringifyedObject);
}

// Checks if the user has any stored data and updates the webpage accordingly
function checkData() {
  let data = getData();

  if (!data) {
    console.log("The user has no data stored");

    setDefault();
    render();

    return false;
  } else {
    console.log("The user has data stored");

    actualData = getData();
    render();

    return true;
  }
}

// Main document objects
const emissionCounter = document.getElementById("emission-counter");
const consentedCounter = document.getElementById("consented-counter");
const housesCounter = document.getElementById("built-counter");
const recycledBottlesCounter = document.getElementById("recycled-counter");
const recycleBtn = document.getElementById("recycle_btn");
const postBtn = document.getElementById("post_btn");

// Variables constantes
const plasticGPerYear = 88_000_000_000; // Grams

// Variables modificables
let homeless = 662_520; // Based on statistics from the Dominican Republic in 2021
let plasticPerBrick = 500; // Grams
let gPerBottle = 20; // Grams
let emissionPerBottle = 82; // Grams
let bricksPerHouse = 5_000; // Bricks
let peoplePerHouse = 5;
let housesNeeded = Math.floor(homeless / peoplePerHouse); // Houses
let bricksNeeded = housesNeeded * bricksPerHouse; // Plastic bricks
let plasticNeeded = bricksNeeded * plasticPerBrick; // Grams
let followersRandomLimit = 1500;

// Data used during execution
let defaultSchema = {
  emission: plasticGPerYear,
  consented: 1,
  recycled: 0,
  homeless: homeless,
  homelessSaved: 0,
  houses: 0,
  recycledTotal: 0,
  plasticGRecycled: 0
};

let actualData = {};

checkData(); // Checking if the user has data

// Button events
recycleBtn.addEventListener("click", e => {
  e.preventDefault();
  recycle();
  updateData();
  render();
});

postBtn.addEventListener('click', e => {
  e.preventDefault();
  doPost();
  updateData();
  render();
});
              
            
!
999px

Console