質問編集履歴
3
追記したことは、別の箇所に記入したため、その部分を削除。
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,38 +26,4 @@
|
|
26
26
|
getWeather(1118370, 2019, 3, 15);//オブジェクトのwoeidプロパティの数値を最初のアーギュメントに代入。
|
27
27
|
```
|
28
28
|
|
29
|
-
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|
29
|
+
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|
30
|
-
|
31
|
-
|
32
|
-
追記
|
33
|
-
|
34
|
-
修正したコード
|
35
|
-
```ここに言語を入力
|
36
|
-
function getLocation(city = 'tok') {
|
37
|
-
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/search/?query=${city}`)
|
38
|
-
.then(result => {
|
39
|
-
return result.json();
|
40
|
-
})
|
41
|
-
.then(data => {
|
42
|
-
tokyoId = data[0].woeid;
|
43
|
-
return tokyoId;
|
44
|
-
})
|
45
|
-
.then(id => {
|
46
|
-
getWeather(id, 2019, 3, 17);
|
47
|
-
})
|
48
|
-
}
|
49
|
-
|
50
|
-
function getWeather(woeId, year, mo, day) {
|
51
|
-
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/${woeId}/${year}/${mo}/${day}/`)
|
52
|
-
.then(result => {
|
53
|
-
return result.json();
|
54
|
-
})
|
55
|
-
.then(data => {
|
56
|
-
console.log(`Temperatures in Tokyo stay between ${data[0].min_temp} and ${data[0].max_temp}.`);
|
57
|
-
|
58
|
-
})
|
59
|
-
.catch(error => console.log(error));
|
60
|
-
}
|
61
|
-
|
62
|
-
getLocation();
|
63
|
-
```
|
2
成功したので新しいコードを追記したいと思います。
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,4 +26,38 @@
|
|
26
26
|
getWeather(1118370, 2019, 3, 15);//オブジェクトのwoeidプロパティの数値を最初のアーギュメントに代入。
|
27
27
|
```
|
28
28
|
|
29
|
-
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|
29
|
+
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|
30
|
+
|
31
|
+
|
32
|
+
追記
|
33
|
+
|
34
|
+
修正したコード
|
35
|
+
```ここに言語を入力
|
36
|
+
function getLocation(city = 'tok') {
|
37
|
+
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/search/?query=${city}`)
|
38
|
+
.then(result => {
|
39
|
+
return result.json();
|
40
|
+
})
|
41
|
+
.then(data => {
|
42
|
+
tokyoId = data[0].woeid;
|
43
|
+
return tokyoId;
|
44
|
+
})
|
45
|
+
.then(id => {
|
46
|
+
getWeather(id, 2019, 3, 17);
|
47
|
+
})
|
48
|
+
}
|
49
|
+
|
50
|
+
function getWeather(woeId, year, mo, day) {
|
51
|
+
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/${woeId}/${year}/${mo}/${day}/`)
|
52
|
+
.then(result => {
|
53
|
+
return result.json();
|
54
|
+
})
|
55
|
+
.then(data => {
|
56
|
+
console.log(`Temperatures in Tokyo stay between ${data[0].min_temp} and ${data[0].max_temp}.`);
|
57
|
+
|
58
|
+
})
|
59
|
+
.catch(error => console.log(error));
|
60
|
+
}
|
61
|
+
|
62
|
+
getLocation();
|
63
|
+
```
|
1
codeタグ内にソースコードの代入。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
ここであるfetchを使った文を書きます。
|
2
|
+
```ここに言語を入力
|
2
3
|
function getLocation(city) {
|
3
4
|
fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/search/?query=${city}`)
|
4
5
|
.then(result => {
|
@@ -23,5 +24,6 @@
|
|
23
24
|
}
|
24
25
|
getLocation('tok');//オブジェクトを表記
|
25
26
|
getWeather(1118370, 2019, 3, 15);//オブジェクトのwoeidプロパティの数値を最初のアーギュメントに代入。
|
27
|
+
```
|
26
28
|
|
27
29
|
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
|