Skip to content

Instantly share code, notes, and snippets.

@mwafrika
Last active August 18, 2019 07:47
Show Gist options
  • Select an option

  • Save mwafrika/727f9c63ce24fcbc97a3bddcca0464cc to your computer and use it in GitHub Desktop.

Select an option

Save mwafrika/727f9c63ce24fcbc97a3bddcca0464cc to your computer and use it in GitHub Desktop.
aboZGxq
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<title>SearchIt</title>
<link href='https://fonts.googleapis.com/css?family=Lobster|Raleway' rel='stylesheet' type='text/css'>
</head>
<style type="text/css">
</style>
<body>
<div class="coll">
<h3 class="text-center"><i class="fa"></i>MY SearchIp</h3>
<div class="form">
<input type="text" name="us_cities" id="search" placeholder="City or State ... "/>
</div>
<div id="match-list"></div>
</div>
</body>
</html>
let countrie;
let search = document.getElementById('search');
let get = document.getElementById('match-list');
const SearchStates = async SearchText => {
let api = 'https://gist.github.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
let response = await fetch(api);
let state = await response.json()
//console.log(state)
let matches = state.filter(stat =>{
const regex = new RegExp(`^${SearchText}`,'gi');
return stat.state.match(regex) || stat.city.match(regex);
});
initialize(matches);
//console.log(matches);
};
console.log(countrie);
SearchStates().then(state=>console.log(state ))
function initialize(getdata){
countrie=getdata;
let option = "";
for(let i=0 ; i< countrie.length;i++){
option += ` <div class = "allElement"> <h1>state: ${countrie[i].state}; city: ${countrie[i].city}; population: ${countrie[i].population} ; growth: ${countrie[i].growth_from_2000_to_2013}.</h1></div> `
if(countrie[i].growth_from_2000_to_2013.length < 0){
return countrie[i].growth_from_2000_to_2013.style.color= "red";
}
};
document.getElementById('match-list').innerHTML= option;
}
search.addEventListener('input',()=> SearchStates(search.value));
/* @font-face {
font-family: 'Lobster';
font-style: normal;
font-weight: 400;
src: local('Lobster Regular'), local('Lobster-Regular'), url(https://fonts.gstatic.com/s/lobster/v22/neILzCirqoswsqX9zo-mM5Ez.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
} */
/* cyrillic */
/* @font-face {
font-family: 'Lobster';
font-style: normal;
font-weight: 400;
src: local('Lobster Regular'), local('Lobster-Regular'), url(https://fonts.gstatic.com/s/lobster/v22/neILzCirqoswsqX9zoamM5Ez.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
} */
/* vietnamese */
/* @font-face {
font-family: 'Lobster';
font-style: normal;
font-weight: 400;
src: local('Lobster Regular'), local('Lobster-Regular'), url(https://fonts.gstatic.com/s/lobster/v22/neILzCirqoswsqX9zo2mM5Ez.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;
} */
/* latin-ext */
/* @font-face {
font-family: 'Lobster';
font-style: normal;
font-weight: 400;
src: local('Lobster Regular'), local('Lobster-Regular'), url(https://fonts.gstatic.com/s/lobster/v22/neILzCirqoswsqX9zoymM5Ez.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} */
/* latin */
/* @font-face {
font-family: 'Lobster';
font-style: normal;
font-weight: 400;
src: local('Lobster Regular'), local('Lobster-Regular'), url(https://fonts.gstatic.com/s/lobster/v22/neILzCirqoswsqX9zoKmMw.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
} */
/* latin-ext */
/* @font-face {
font-family: 'Raleway';
font-style: normal;
font-weight: 400;
src: local('Raleway'), local('Raleway-Regular'), url(https://fonts.gstatic.com/s/raleway/v14/1Ptug8zYS_SKggPNyCMIT5lu.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
} */
/* latin */
/* @font-face {
font-family: 'Raleway';
font-style: normal;
font-weight: 400;
src: local('Raleway'), local('Raleway-Regular'), url(https://fonts.gstatic.com/s/raleway/v14/1Ptug8zYS_SKggPNyC0ITw.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
} */
body {
width: 800px;
margin: 0 auto;
}
.text-center{
float:right;
width:300px;
margin-top: 110px;
font-size:30px;
font-family: 'Lobster', cursive;
color: blue;
background-image: linear-gradient(snow, yellow);
}
#search{
width: 50%;
height: 60px;
margin: 100px 0;
padding: 12px 20px;
box-sizing: border-box;
border:2px solid blue;
border-radius: 4px;
}
input[type=text]{
background-color: snow;
color: black;
outline: none;
font-size:20px;
}
inpu[placeholder]{
color: lightgrey;
}
.allElement{
font-size: 10px;
border: 1px solid blue;
text-orientation: none ;
text-align: center;
margin: 3px;
background-color: snow;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment