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

Commit 0f392f1

Browse files
committed
solve linter issue
1 parent d78c869 commit 0f392f1

File tree

1 file changed

+30
-33
lines changed

1 file changed

+30
-33
lines changed

Source-Code/WeatherApp/script.js

Lines changed: 30 additions & 33 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 countryy = 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 countryy = 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);
@@ -29,9 +29,9 @@ const updateWeatherInfo = (result) => {
2929
if (error) {
3030
cityName.innerText = `Error: ${error.message}`;
3131
[countryy, dateTime, temp, humidity, condition2, icon].forEach((elem) => {
32-
elem.innerText = "";
32+
elem.innerText = '';
3333
});
34-
icon.src = "";
34+
icon.src = '';
3535
} else {
3636
const { name, country, localtime } = location;
3737
console.log(country);
@@ -43,7 +43,7 @@ const updateWeatherInfo = (result) => {
4343
condition2.innerText = current.condition.text;
4444
icon.src = current.condition.icon;
4545

46-
const isDay = current.is_day === 1 ? "day" : "night";
46+
const isDay = current.is_day === 1 ? 'day' : 'night';
4747
const codes = [
4848
[1000, 10000, 10001, 1100, 11001, 11000, 51190, 60030], // clear
4949
[
@@ -78,38 +78,37 @@ const updateWeatherInfo = (result) => {
7878
const getData = async (cityName) => {
7979
try {
8080
const result = await fetchData(
81-
`https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${cityName}&aqi=no`
81+
`https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${cityName}&aqi=no`,
8282
);
8383
return result;
8484
} catch (error) {
8585
return {
86-
error: { message: "Failed to fetch data. Please try again later." },
86+
error: { message: 'Failed to fetch data. Please try again later.' },
8787
};
8888
}
8989
};
90-
const getlocation = async (lat, long) =>
91-
fetchData(
92-
`https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${lat},${long}&aqi=no`
93-
);
90+
const getlocation = async (lat, long) => fetchData(
91+
`https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${lat},${long}&aqi=no`,
92+
);
9493

9594
const gotlocation = async (position) => {
9695
try {
9796
const result = await getlocation(
9897
position.coords.latitude,
99-
position.coords.longitude
98+
position.coords.longitude,
10099
);
101100
console.log(result);
102101
updateWeatherInfo(result);
103102
} catch (error) {
104-
cityName.innerText = "Error fetching weather based on location";
103+
cityName.innerText = 'Error fetching weather based on location';
105104
}
106105
};
107-
const failedlocation = () => console.log("failed to locate location");
106+
const failedlocation = () => console.log('failed to locate location');
108107

109-
btn.addEventListener("click", async (e) => {
108+
btn.addEventListener('click', async (e) => {
110109
try {
111110
if (input.value.length === 0) {
112-
alert("Please type a city name");
111+
alert('Please type a city name');
113112
} else {
114113
const { value } = input;
115114
const result = await getData(value);
@@ -118,23 +117,21 @@ btn.addEventListener("click", async (e) => {
118117
console.log(result);
119118
}
120119
} catch (error) {
121-
cityName.innerText = "Error to fetch weather";
120+
cityName.innerText = 'Error to fetch weather';
122121
}
123122
e.preventDefault();
124123
});
125124

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

138-
window.addEventListener("load", async () => {
135+
window.addEventListener('load', async () => {
139136
navigator.geolocation.getCurrentPosition(gotlocation, failedlocation);
140137
});

0 commit comments

Comments
 (0)