Coder Social home page Coder Social logo

us-city-population's Introduction

US City Population

US City Population is a website that helps you search for population of US cities.

Table of contents

Overview

Screenshots

US City Population website screenshot US City Population website screenshot US City Population website screenshot

us-city-population-demo-vid.mov

Demo Link

๐Ÿ’ป Live Site URL

About the Project

Status

โœ… Completed & Deployed

Built with

  • HTML
  • CSS
  • Vanilla JS

Reflection

This was another Vanilla JS project from JavaScript 30 course by Wes Bos using GitHub gist from 1000 Largest US Cities By Population With Geographic Coordinates, in JSON.

Some features to highlight in this project are:

  • using async/await function to fetch data.

    // Fetch API data
    async function fetchData(searchQuery) {
      const res = await fetch(endpoint);
      const data = await res.json();
      if (!res.ok) {
        throw Error(res.statusText);
      }
    
      const neededData = await data.map(item => ({
        city: item.city,
        state: item.state,
        population: item.population,
      }));
    
      apiData.push(...neededData);
    }
    fetchData();
  • using RegExp() constructor to create a regular expression to match input value with the fetched data.

    // Find matching words
    function findMatches(wordToMatch, apiData) {
      const regex = new RegExp(wordToMatch, "gi");
      return apiData.filter(
        item => item.city.match(regex) || item.state.match(regex)
      );
    }
  • using innerHTML property to change the HTML content of element.

One of the challenges I faced as I was building this app was using regular expressions. Initially, when I was building the app on my own, I tried to make a complex logic to try to match the input value with the fetched data. However, after listening to the lecture, I realized that all of that process becomes so much simpler and cleaner to code when I use RegExp.

Author

Soojeong Park @codingsooj

us-city-population's People

Contributors

soojeong-park-ca avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.