-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.js
More file actions
60 lines (54 loc) · 1.42 KB
/
weather.js
File metadata and controls
60 lines (54 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const state = reactive({selectedCity: 'London',
weather: {
temperature: 'N/A',
humidity: 'N/A',
description: ''
}})
const mockWeatherData = {
"New York": {
temperature: '15°C',
humidity: '55%',
description: 'Cloudy'
},
"London": {
temperature: '10°C',
humidity: '75%',
description: 'Rainy'
},
"Tokyo": {
temperature: '22°C',
humidity: '65%',
description: 'Sunny'
},
"Sydney": {
temperature: '25°C',
humidity: '60%',
description: 'Sunny'
}
};
function fetchWeather (city) {
setTimeout(() => {
const weather = mockWeatherData[city]
state.weather = weather;
}, 500)
}
createEffect(function() {
fetchWeather(state.selectedCity)
})
createEffect (function() {
render(`#container`, `<select onChange=updateSelectedCity(this.value)>
<option value='Tokyo'>Tokyo</option>
<option value='London'>London</option>
<option value='New York'>New York</option>
<option value='Sydney'>Sydney</option>
</select>
<div>
<p>Temperature: ${state.weather.temperature}</p>
<p>Humidity: ${state.weather.humidity}</p>
<p>Description: ${state.weather.description}</p>
</div>`)
})
function updateSelectedCity (city) {
state.selectedCity = city
fetchWeather(city);
}