Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 18220e8

Browse files
committed
solve linter issue
1 parent e1bd500 commit 18220e8

File tree

2 files changed

+52
-49
lines changed

2 files changed

+52
-49
lines changed

Source-Code/WeatherApp/script.js

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const input = document.getElementById("input");
2-
const btn = document.getElementById("btn");
3-
const apiKey = "e3a46268fdc2475cb63214712240202";
4-
const cityName = document.getElementById("city-name");
5-
const dateTime = document.getElementById("date-time");
6-
const condition2 = document.getElementById("condition2");
7-
const temp = document.getElementById("temp");
8-
const humidity = document.getElementById("humidity");
9-
const country = document.getElementById("country");
10-
const locat = document.getElementById("getlocation");
11-
const cities = document.getElementsByClassName("city");
12-
const icon = document.getElementById("icon");
13-
const body = document.querySelector(".weather-app");
1+
const input = document.getElementById('input');
2+
const btn = document.getElementById('btn');
3+
const apiKey = 'e3a46268fdc2475cb63214712240202';
4+
const cityName = document.getElementById('city-name');
5+
const dateTime = document.getElementById('date-time');
6+
const condition2 = document.getElementById('condition2');
7+
const temp = document.getElementById('temp');
8+
const humidity = document.getElementById('humidity');
9+
const country = document.getElementById('country');
10+
const locat = document.getElementById('getlocation');
11+
const cities = document.getElementsByClassName('city');
12+
const icon = document.getElementById('icon');
13+
const body = document.querySelector('.weather-app');
1414
const fetchData = async (url) => {
1515
try {
1616
const data = await fetch(url);
@@ -27,11 +27,11 @@ const fetchData = async (url) => {
2727
const updateWeatherInfo = (result) => {
2828
const { error, location, current } = result;
2929
if (error) {
30-
cityName.innerText = "Error: " + error.message;
31-
[country, dateTime, temp, humidity, condition2, icon].forEach(
32-
(elem) => (elem.innerText = "")
33-
);
34-
icon.src = "";
30+
cityName.innerText = `Error: ${error.message}`;
31+
[country, dateTime, temp, humidity, condition2, icon].forEach((elem) => {
32+
elem.innerText = '';
33+
});
34+
icon.src = '';
3535
} else {
3636
const { name, country, localtime } = location;
3737
cityName.innerText = name;
@@ -42,7 +42,7 @@ const updateWeatherInfo = (result) => {
4242
condition2.innerText = current.condition.text;
4343
icon.src = current.condition.icon;
4444

45-
const isDay = current.is_day == 1 ? "day" : "night";
45+
const isDay = current.is_day === 1 ? 'day' : 'night';
4646
const codes = [
4747
[1000, 10000, 10001, 1100, 11001, 11000, 51190, 60030], // clear
4848
[
@@ -65,7 +65,7 @@ const updateWeatherInfo = (result) => {
6565
`./images/${isDay}/snowy.jpg`,
6666
];
6767

68-
for (let i = 0; i < codes.length; i++) {
68+
for (let i = 0; i < codes.length; i += 1) {
6969
if (codes[i].includes(current.condition.code)) {
7070
body.style.backgroundImage = `url('${imageUrls[i]}')`;
7171
console.log(imageUrls[i]);
@@ -77,38 +77,37 @@ const updateWeatherInfo = (result) => {
7777
const getData = async (cityName) => {
7878
try {
7979
const result = await fetchData(
80-
`http://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${cityName}&aqi=no`
80+
`http://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${cityName}&aqi=no`,
8181
);
8282
return result;
8383
} catch (error) {
8484
return {
85-
error: { message: "Failed to fetch data. Please try again later." },
85+
error: { message: 'Failed to fetch data. Please try again later.' },
8686
};
8787
}
8888
};
89-
const getlocation = async (lat, long) =>
90-
fetchData(
91-
`http://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${lat},${long}&aqi=no`
92-
);
89+
const getlocation = async (lat, long) => fetchData(
90+
`http://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${lat},${long}&aqi=no`,
91+
);
9392

9493
const gotlocation = async (position) => {
9594
try {
9695
const result = await getlocation(
9796
position.coords.latitude,
98-
position.coords.longitude
97+
position.coords.longitude,
9998
);
10099
console.log(result);
101100
updateWeatherInfo(result);
102101
} catch (error) {
103-
cityName.innerText = "Error fetching weather based on location";
102+
cityName.innerText = 'Error fetching weather based on location';
104103
}
105104
};
106-
const failedlocation = () => console.log("failed to locate location");
105+
const failedlocation = () => console.log('failed to locate location');
107106

108-
btn.addEventListener("click", async (e) => {
107+
btn.addEventListener('click', async (e) => {
109108
try {
110109
if (input.value.length === 0) {
111-
alert("Please type a city name");
110+
alert('Please type a city name');
112111
} else {
113112
const { value } = input;
114113
const result = await getData(value);
@@ -117,23 +116,21 @@ btn.addEventListener("click", async (e) => {
117116
console.log(result);
118117
}
119118
} catch (error) {
120-
cityName.innerText = "Error to fetch weather";
119+
cityName.innerText = 'Error to fetch weather';
121120
}
122121
e.preventDefault();
123122
});
124123

125-
locat.addEventListener("click", () =>
126-
navigator.geolocation.getCurrentPosition(gotlocation, failedlocation)
127-
);
124+
locat.addEventListener('click', () => navigator.geolocation.getCurrentPosition(gotlocation, failedlocation));
128125
const citiesArray = [...cities];
129126
citiesArray.forEach((element) => {
130-
element.addEventListener("click", async () => {
127+
element.addEventListener('click', async () => {
131128
const cityName = element.innerText;
132129
const result = await getData(cityName);
133130
updateWeatherInfo(result);
134131
});
135132
});
136133

137-
window.addEventListener("load", async () => {
134+
window.addEventListener('load', async () => {
138135
navigator.geolocation.getCurrentPosition(gotlocation, failedlocation);
139136
});

Source-Code/WeatherApp/style.css

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
margin: 0;
55
}
66

7-
p, span {
7+
p,
8+
span {
89
font-size: 18px;
910
}
1011

1112
.weather-app {
1213
min-height: 100vh;
1314
min-width: 100vw;
14-
background-position: center;
15+
background-position: center;
1516
background-repeat: no-repeat;
16-
background-size: cover;
17+
background-size: cover;
1718
position: relative;
1819
color: #fff;
1920
transition: 500ms linear;
@@ -26,7 +27,7 @@ p, span {
2627
left: 0;
2728
width: 100%;
2829
height: 100%;
29-
background: rgba(0,0,0,0.3);
30+
background: rgba(0, 0, 0, 0.3);
3031
z-index: 0;
3132
}
3233

@@ -57,7 +58,7 @@ li {
5758
.weather-information {
5859
display: flex;
5960
flex-direction: row;
60-
align-items: flex-end;
61+
align-items: flex-end;
6162
padding: 5% 5%;
6263
gap: 5%;
6364
justify-content: space-evenly;
@@ -82,10 +83,12 @@ li {
8283
width: 40vw;
8384
height: 100vh;
8485
background: rgba(236, 236, 178, 0.104);
85-
box-shadow: 0 8px 32px 0 rgba(0,0,0,0.3);
86+
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
8687
backdrop-filter: blur(5px);
88+
8789
--webkit-backdrop-filter: blur(5px);
88-
border: 1px solid rgb(236, 236, 178,0);
90+
91+
border: 1px solid rgb(236, 236, 178, 0);
8992
z-index: 1;
9093
padding: 2em 2em;
9194
}
@@ -167,12 +170,14 @@ span {
167170
margin: 6%;
168171
}
169172

170-
.weather-suggestions .city, .location {
173+
.weather-suggestions .city,
174+
.location {
171175
display: block;
172176
cursor: pointer;
173177
}
174178

175-
.weather-suggestions .city:hover, .location:hover {
179+
.weather-suggestions .city:hover,
180+
.location:hover {
176181
color: #ffffffc8;
177182
transform: scale(1.2);
178183
transition: 0.5s;
@@ -184,8 +189,9 @@ span {
184189
flex-direction: column;
185190
width: 100%;
186191
}
187-
188-
.weather-suggestions, .weather-information {
192+
193+
.weather-suggestions,
194+
.weather-information {
189195
width: 100%;
190196
}
191197

@@ -202,4 +208,4 @@ span {
202208
.weather-information {
203209
gap: 1%;
204210
}
205-
}
211+
}

0 commit comments

Comments
 (0)