質問編集履歴
3
追記したことは、別の箇所に記入したため、その部分を削除。
test
CHANGED
File without changes
|
test
CHANGED
@@ -55,71 +55,3 @@
|
|
55
55
|
|
56
56
|
|
57
57
|
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
追記
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
修正したコード
|
68
|
-
|
69
|
-
```ここに言語を入力
|
70
|
-
|
71
|
-
function getLocation(city = 'tok') {
|
72
|
-
|
73
|
-
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/search/?query=${city}`)
|
74
|
-
|
75
|
-
.then(result => {
|
76
|
-
|
77
|
-
return result.json();
|
78
|
-
|
79
|
-
})
|
80
|
-
|
81
|
-
.then(data => {
|
82
|
-
|
83
|
-
tokyoId = data[0].woeid;
|
84
|
-
|
85
|
-
return tokyoId;
|
86
|
-
|
87
|
-
})
|
88
|
-
|
89
|
-
.then(id => {
|
90
|
-
|
91
|
-
getWeather(id, 2019, 3, 17);
|
92
|
-
|
93
|
-
})
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
function getWeather(woeId, year, mo, day) {
|
100
|
-
|
101
|
-
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/${woeId}/${year}/${mo}/${day}/`)
|
102
|
-
|
103
|
-
.then(result => {
|
104
|
-
|
105
|
-
return result.json();
|
106
|
-
|
107
|
-
})
|
108
|
-
|
109
|
-
.then(data => {
|
110
|
-
|
111
|
-
console.log(`Temperatures in Tokyo stay between ${data[0].min_temp} and ${data[0].max_temp}.`);
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
})
|
116
|
-
|
117
|
-
.catch(error => console.log(error));
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
getLocation();
|
124
|
-
|
125
|
-
```
|
2
成功したので新しいコードを追記したいと思います。
test
CHANGED
File without changes
|
test
CHANGED
@@ -55,3 +55,71 @@
|
|
55
55
|
|
56
56
|
|
57
57
|
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
追記
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
修正したコード
|
68
|
+
|
69
|
+
```ここに言語を入力
|
70
|
+
|
71
|
+
function getLocation(city = 'tok') {
|
72
|
+
|
73
|
+
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/search/?query=${city}`)
|
74
|
+
|
75
|
+
.then(result => {
|
76
|
+
|
77
|
+
return result.json();
|
78
|
+
|
79
|
+
})
|
80
|
+
|
81
|
+
.then(data => {
|
82
|
+
|
83
|
+
tokyoId = data[0].woeid;
|
84
|
+
|
85
|
+
return tokyoId;
|
86
|
+
|
87
|
+
})
|
88
|
+
|
89
|
+
.then(id => {
|
90
|
+
|
91
|
+
getWeather(id, 2019, 3, 17);
|
92
|
+
|
93
|
+
})
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
function getWeather(woeId, year, mo, day) {
|
100
|
+
|
101
|
+
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/${woeId}/${year}/${mo}/${day}/`)
|
102
|
+
|
103
|
+
.then(result => {
|
104
|
+
|
105
|
+
return result.json();
|
106
|
+
|
107
|
+
})
|
108
|
+
|
109
|
+
.then(data => {
|
110
|
+
|
111
|
+
console.log(`Temperatures in Tokyo stay between ${data[0].min_temp} and ${data[0].max_temp}.`);
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
})
|
116
|
+
|
117
|
+
.catch(error => console.log(error));
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
getLocation();
|
124
|
+
|
125
|
+
```
|
1
codeタグ内にソースコードの代入。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
ここであるfetchを使った文を書きます。
|
2
|
+
|
3
|
+
```ここに言語を入力
|
2
4
|
|
3
5
|
function getLocation(city) {
|
4
6
|
|
@@ -48,6 +50,8 @@
|
|
48
50
|
|
49
51
|
getWeather(1118370, 2019, 3, 15);//オブジェクトのwoeidプロパティの数値を最初のアーギュメントに代入。
|
50
52
|
|
53
|
+
```
|
54
|
+
|
51
55
|
|
52
56
|
|
53
57
|
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|