Skip to content

Commit 469b7ec

Browse files
Updated filter condition
1 parent c82292a commit 469b7ec

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

script/script.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ const storyData = [
123123
const defaultData = {
124124
location: "Location Not Found",
125125
title: "Dummy Title",
126-
story: `Brampton is a city in the Canadian province of Ontario. Situated in Southern Ontario, it is a suburban city in the Greater Toronto Area (GTA) and the seat of Peel Region. The city has a population of 593,638 as of the Canada 2016 Census. Brampton is Canada's ninth-most populous municipality, the seventy-seventh largest city in North America and the third most populous city in the Greater Golden Horseshoe Region, behind Toronto and Mississauga.[2]
126+
story: `DEVASHSHISH DEVASHISH DEVASHSIH Brampton is a city in the Canadian province of Ontario. Situated in Southern Ontario, it is a suburban city in the Greater Toronto Area (GTA) and the seat of Peel Region. The city has a population of 593,638 as of the Canada 2016 Census. Brampton is Canada's ninth-most populous municipality, the seventy-seventh largest city in North America and the third most populous city in the Greater Golden Horseshoe Region, behind Toronto and Mississauga.[2]
127127
128128
Brampton was incorporated as a village in 1853 with 50 residents, taking its name from the market town of Brampton, in Cumbria, England. In 1873, with 2,000 residents, Brampton was incorporated as a town. The city was once known as "The Flower Town of Canada", a title based on its large greenhouse industry. Today, Brampton's major economic sectors include advanced manufacturing, retail administration, logistics, information, and communication technologies, food and beverage, life sciences, and business services. Mass immigration has greatly increased Brampton's population from 10,000 in the 1950s to over 600,000 today. `,
129-
image: {
130-
img1: "img/ahmedabad/ahmedabad1.jpg",
131-
img2: "img/ahmedabad/ahmedabad1.jpg",
132-
img3: "img/ahmedabad/ahmedabad1.jpg"
133-
}
129+
images: [
130+
"img/ahmedabad/ahmedabad1.jpg",
131+
"img/ahmedabad/ahmedabad2.png",
132+
"img/ahmedabad/ahmedabad3.jpg"
133+
]
134134
};
135135
const app = {};
136136
const apiKeys = {
@@ -182,7 +182,7 @@ app.getData = addressInput => {
182182
app.filter = data => {
183183
const arr = data.results[0].address_components;
184184

185-
return (cityName = arr.filter(arr => arr.types.includes("locality"))[0]
185+
return (cityName = arr.filter(arr => arr.types.includes("political"))[0]
186186
.long_name);
187187

188188
// Idea of filtering:
@@ -231,20 +231,22 @@ app.empty = () => {
231231
// displaying the data to DOM
232232

233233
app.displayStoryContent = data => {
234-
// console.log(data);
235234
const cityName = app.filter(data);
236235
$(".addressTitle").append(data.results[0].formatted_address);
237-
// Display Story
238-
storyData.forEach(stry => {
239-
if (cityName.toLowerCase() === stry.location.toLowerCase()) {
240-
$(".story-title").append(stry.title);
241-
$(".story-content").append(stry.story);
242-
// Displaying Images
243-
let imgContent = "";
244-
stry.images.forEach((imageLink, index) => {
245-
return (imgContent =
246-
imgContent +
247-
`<img
236+
237+
const result = storyData.filter(
238+
location => cityName.toLowerCase() === location.location.toLowerCase()
239+
);
240+
//displaying the data
241+
if (result.length !== 0) {
242+
$(".story-title").append(result[0].title);
243+
$(".story-content").append(result[0].story);
244+
// Displaying Images
245+
let imgContent = "";
246+
result[0].images.forEach((imageLink, index) => {
247+
return (imgContent =
248+
imgContent +
249+
`<img
248250
srcset="
249251
${imageLink} 300w,
250252
${imageLink} 1000w
@@ -254,10 +256,31 @@ app.displayStoryContent = data => {
254256
class="composition__photo composition__photo--p${index + 1}"
255257
src="${imageLink}"
256258
/>`);
257-
});
258-
$(".composition").append(imgContent);
259-
}
260-
});
259+
});
260+
$(".composition").append(imgContent);
261+
}
262+
//Default Data
263+
else {
264+
$(".story-title").append(defaultData.title);
265+
$(".story-content").append(defaultData.story);
266+
// Displaying Images
267+
let imgContent = "";
268+
defaultData.images.forEach((imageLink, index) => {
269+
return (imgContent =
270+
imgContent +
271+
`<img
272+
srcset="
273+
${imageLink} 300w,
274+
${imageLink} 1000w
275+
"
276+
sizes="(max-width: 56.25em) 20vw, (max-width: 37.5em) 30vw, auto"
277+
alt="Photo 1"
278+
class="composition__photo composition__photo--p${index + 1}"
279+
src="${imageLink}"
280+
/>`);
281+
});
282+
$(".composition").append(imgContent);
283+
}
261284
};
262285

263286
// Getting Local Time for the searched location and displaying to DOM

0 commit comments

Comments
 (0)