Giter VIP home page Giter VIP logo

myjavascript30's Introduction

7th- City Search Project - Learning Documentation

Overview

This project is a simple web application that fetches city data from an external API, allows users to search for cities, and displays population data. The goal of this project was to gain hands-on experience with HTML, CSS, and JavaScript, and to learn about data fetching, filtering, and UI updates.

Lessons Learned

1. Fetching Data with fetch API

I gained an understanding of how to fetch data from an external API using the fetch API in JavaScript. The process involves making a network request, handling the response, and using the data in the application.

fetch(endpoint)
  .then(response => response.json())
  .then(data => cities.push(...data));

2. Dynamic UI Updates

I learned how to dynamically update the user interface based on user input. The displayMatches function is triggered on change and keyup events on the search input, updating the displayed city results.

const searchInput = document.querySelector('.search');
searchInput.addEventListener('change', displayMatches);
searchInput.addEventListener('keyup', displayMatches);

3. Regular Expressions for String Matching

Regular expressions (regex) were used to match and highlight parts of the city and state names that match the search term. This allowed for a more user-friendly display of search results.

const regex = new RegExp(this.value, 'gi');
const cityName = place.city.replace(regex, `<span class="hl">${this.value}</span>`);

4. Working with HTML, CSS, and JavaScript

The project involved working with the core web technologies: HTML for structuring the page, CSS for styling, and JavaScript for adding interactivity. This helped reinforce the fundamental concepts of web development.

5. Handling Asynchronous Operations

I encountered asynchronous operations when fetching data using fetch. This led to a better understanding of promises and how to handle asynchronous code using .then().

fetch(endpoint)
  .then(response => response.json())
  .then(data => cities.push(...data));

6. Template Literals and String Manipulation

Template literals were used for creating dynamic HTML strings. This allowed for easy concatenation of strings and variables, improving code readability.

return `
  <li>
    <span class="name">${cityName}, ${stateName}</span>
    <span class="population">${numberWithCommas(place.population)}</span>
  </li>
`;

Future Improvements and Challenges

While working on this project, I identified areas for improvement and encountered challenges:

Future Improvements

  • Error Handling: Enhance the application with proper error handling during data fetching to provide a better user experience.

  • Pagination: Implement pagination for large datasets to improve performance and user interaction.

  • UI Enhancements: Add more features to enhance the user interface, such as sorting options and additional details about each city.

Challenges

  • Async/Await: The asynchronous nature of data fetching required a clear understanding of promises and the use of .then(). Exploring async/await syntax could simplify the code further.

  • Dynamic Highlighting: Achieving dynamic highlighting in search results using regular expressions required experimentation and testing.

Summary

This project provided a practical learning experience in web development, covering fundamental concepts such as data fetching, UI updates, regular expressions, and asynchronous operations.

myjavascript30's People

Contributors

likemcode avatar

Stargazers

 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.