Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Type Ahead 👀</title>
- <link rel="stylesheet" href="style.css">
- </head>
- <body>
- <form class="search-form">
- <input type="text" class="search" placeholder="City or State">
- <ul class="suggestions">
- <li>Filter for a city</li>
- <li>or a state</li>
- </ul>
- </form>
- <script>
- const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
- const cities = [];
- fetch(endpoint)
- .then(blob => blob.json())
- .then(data => cities.push(...data))
- function findMatches(wordtoMatch, cities){
- return cities.filter(place => {
- const regex = new RegExp(wordtoMatch, 'gi');
- return place.city.match(regex) || place.state.match(regex)
- })
- }
- function displayMatches(){
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement