Home Web Front-end JS Tutorial Building \'The People Counter\': A Journey from Childhood Counting to Modern Website

Building \'The People Counter\': A Journey from Childhood Counting to Modern Website

Aug 18, 2024 am 12:00 AM

Building \

Introduction

Ever find yourself counting people or objects just for fun? I certainly did as a child, whether it was the number of cars passing by or how many people were in a room. This simple habit sparked the idea behind my project: The People Counter.

The primary goal of creating The People Counter was to dive into JavaScript, understand its syntax, and get comfortable with its flow. While I named it “The People Counter,” the concept is versatile and can be adapted to any type of counter—be it a car counter, house counter, toffee counter, or even a star counter. It’s fundamentally a counter app that helps in grasping the basics of JavaScript programming.

This project was built using resources from the Scrimba learning platform, which provided valuable insights and guidance throughout the development process.

Click to view the app in action!

The People Counter is designed to provide an easy, effective way to track and manage counts, all while showcasing the power of HTML, CSS, and JavaScript.

Features That Make Counting Fun

  1. Real-Time Counting
    Keep track of your count with a simple click of the "Increment" button. No more manual tallying!
    <button id="increment-btn" onclick="increment()">Increment</button>
    This feature updates the displayed count instantly each time you click the button.

  2. Save and View Entries
    Log your counts and view a history of previous entries. Perfect for keeping track of multiple counts over time.
    <button id="save-btn" onclick="save()">Save</button>
    <div id="save-el" class="entry-list"></div>
    Saved counts are added to a list below the button, allowing you to review your count history.

  3. Elegant and Responsive Design
    The app adapts seamlessly to various screen sizes, ensuring a clean, modern interface whether you're on a desktop or mobile device.
    The app’s design looks great on all devices, enhancing user experience.

Technologies That Power the App

HTML : The backbone of the application, providing the essential structure.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

&lt;!DOCTYPE html&gt;

&lt;html lang="en"&gt;

&lt;head&gt;

    &lt;meta charset="UTF-8"&gt;

    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;

    &lt;link rel="stylesheet" href="index.css"&gt;

    &lt;link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&amp;family=Lato:wght@300;400;700&amp;display=swap" rel="stylesheet"&gt;

    &lt;title&gt;The People Counter&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;

    &lt;div class="app-container"&gt;

        &lt;header&gt;

            &lt;h1&gt;The People Counter&lt;/h1&gt;

        &lt;/header&gt;

        &lt;main class="counter-container"&gt;

            &lt;div class="counter-display"&gt;

                &lt;div class="counter-frame"&gt;

                    &lt;div id="count-el"&gt;0&lt;/div&gt;

                &lt;/div&gt;

            &lt;/div&gt;

            &lt;div class="controls"&gt;

                &lt;button id="increment-btn" onclick="increment()"&gt;

                    &lt;span&gt;Increment&lt;/span&gt;

                &lt;/button&gt;

                &lt;button id="save-btn" onclick="save()"&gt;

                    &lt;span&gt;Save&lt;/span&gt;

                &lt;/button&gt;

            &lt;/div&gt;

            &lt;div class="entries"&gt;

                &lt;h2&gt;Previous Entries&lt;/h2&gt;

                &lt;div id="save-el" class="entry-list"&gt;&lt;/div&gt;

            &lt;/div&gt;

        &lt;/main&gt;

    &lt;/div&gt;

    &lt;script src="index.js"&gt;&lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;

Copy after login

CSS
For styling the app, you can use CSS to make it visually appealing and responsive. (Since this section is focused more on JavaScript, I'll skip detailed CSS here.)

JavaScript
Bringing interactivity to the app with dynamic functionality.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

let count = 0

 

let countEl = document.getElementById("count-el")

 

let saveEl = document.getElementById ("save-el")

 

 

function increment() {  

    count += 1

    countEl.textContent = count

}

 

function save() {

    let countStr = count + " - "

    saveEl.textContent += countStr

    countEl.textContent = 0

    count = 0

}

Copy after login

Explanation:

Variables Declaration:

  • let count = 0;: Initializes a variable count to keep track of the number of increments.
  • let countEl = document.getElementById("count-el");: Retrieves the HTML element where the current count is displayed and assigns it to countEl.
  • let saveEl = document.getElementById("save-el");: Retrieves the HTML element where the saved counts will be displayed and assigns it to saveEl.

increment Function:

  • count += 1;: Increases the count variable by 1 each time the function is called.
  • countEl.textContent = count;: Updates the displayed count in the countEl element to reflect the new value.

save Function:

  • let countStr = count + " - ";: Creates a string from the current count and appends a dash for separation.
  • saveEl.textContent += countStr;: Adds the new count string to the existing list of saved counts in the saveEl element.
  • countEl.textContent = 0;: Resets the displayed count to 0 after saving.
  • count = 0;: Resets the count variable to 0 to start fresh for the next counting session.

How to Use the App

Increment the Count:
Click the "Increment" button to increase the count by 1. The number displayed will update in real-time.

Save the Count:
Click the "Save" button to log the current count. The count will be added to the list of previous entries, and the display will reset to 0.

View Previous Entries:
The saved counts will appear below the "Previous Entries" section, where you can review your count history.

Lessons Learned

Building The People Counter was an insightful experience, particularly following a tutorial on Scrimba. It reinforced key concepts in HTML, CSS, and JavaScript and demonstrated how to create a functional, responsive web application.

Conclusion

The People Counter serves as a testament to how simple ideas can evolve into practical tools with a bit of coding knowledge. Whether you're tracking people, objects, or just having fun with numbers, this app provides a modern solution for an age-old habit.

The above is the detailed content of Building \'The People Counter\': A Journey from Childhood Counting to Modern Website. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

Custom Google Search API Setup Tutorial

Example Colors JSON File Example Colors JSON File Mar 03, 2025 am 12:35 AM

Example Colors JSON File

10 jQuery Syntax Highlighters 10 jQuery Syntax Highlighters Mar 02, 2025 am 12:32 AM

10 jQuery Syntax Highlighters

8 Stunning jQuery Page Layout Plugins 8 Stunning jQuery Page Layout Plugins Mar 06, 2025 am 12:48 AM

8 Stunning jQuery Page Layout Plugins

Build Your Own AJAX Web Applications Build Your Own AJAX Web Applications Mar 09, 2025 am 12:11 AM

Build Your Own AJAX Web Applications

What is 'this' in JavaScript? What is 'this' in JavaScript? Mar 04, 2025 am 01:15 AM

What is 'this' in JavaScript?

10  JavaScript & jQuery MVC Tutorials 10 JavaScript & jQuery MVC Tutorials Mar 02, 2025 am 01:16 AM

10 JavaScript & jQuery MVC Tutorials

See all articles