Skip to content

Commit 2649029

Browse files
committed
travel app almost ready
1 parent c34f101 commit 2649029

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

travelRecommendation/travel_recommendation.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ function searchCondition() {
88
const resultDiv = document.getElementById('result');
99
resultDiv.innerHTML = '';
1010

11-
fetch('travel_recommendation_api.json')
11+
fetch('./travel_recommendation_api.json')
1212
.then(response => response.json())
1313

1414
.then(data => {
1515
const country = data.countries.find(item => item.name.toLowerCase() === input);
16-
console.log(country);
17-
const temple = data.temples.find('temple' === input);
18-
const beach = data.beaches.find(item => item.name.toLowerCase() === input);
16+
const temple = data.temples.find(item => 'temple' === input);
17+
const beach = data.beaches.find(item => 'beach' === input);
1918

2019
//search for country
2120
if (country) {
@@ -29,13 +28,21 @@ function searchCondition() {
2928

3029
//search for temple
3130
else if (temple) {
32-
console.log(data.temples.length);
33-
console.log(data.temples[0]);
34-
console.log(data.temples[1]);
35-
for (let i = 0; i <= temple.temples.length - 1; i++) {
36-
resultDiv.innerHTML += `<h2>${temples[i].name}</h2>`;
37-
resultDiv.innerHTML += `<img src="${temples[i].imageUrl}" alt="hjh">`;
38-
resultDiv.innerHTML += `<p><strong>Description:</strong> ${temples[i].description}</p>`;
31+
console.log(data.temples.length);
32+
for (let j = 0; j <= data.temples.length - 1; j++) {
33+
resultDiv.innerHTML += `<h2>${data.temples[j].name}</h2>`;
34+
resultDiv.innerHTML += `<img src="${data.temples[j].imageUrl}" alt="hjh">`;
35+
resultDiv.innerHTML += `<p><strong>Description:</strong> ${data.temples[j].description}</p>`;
36+
}
37+
}
38+
39+
//search for beach
40+
else if (beach) {
41+
console.log(data.beaches.length);
42+
for (let z = 0; z <= data.beaches.length - 1; z++) {
43+
resultDiv.innerHTML += `<h2>${data.beaches[z].name}</h2>`;
44+
resultDiv.innerHTML += `<img src="${data.beaches[z].imageUrl}" alt="hjh">`;
45+
resultDiv.innerHTML += `<p><strong>Description:</strong> ${data.beaches[z].description}</p>`;
3946
}
4047
}
4148

@@ -50,4 +57,5 @@ function searchCondition() {
5057
});
5158
}
5259
btnSearch.addEventListener('click', searchCondition);
53-
//console.log("Pressed button!");
60+
61+
f

0 commit comments

Comments
 (0)