ここであるfetchを使った文を書きます。
function getLocation(city) { fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/search/?query=${city}`) .then(result => { return result.json(); }) .then(data => { console.log(data[0]); }) } function getWeather(woeId, year, mo, day) { fetch(`https://cors-anywhere.herokuapp.com/www.metaweather.com/api/location/${woeId}/${year}/${mo}/${day}/`) .then(result => { return result.json(); }) .then(data => { // const today = data.consolidated_weather[0]; console.log(`Temperatures in Tokyo stay between ${data[0].min_temp} and ${data[0].max_temp}.`); }) .catch(error => console.log(error)); } getLocation('tok');//オブジェクトを表記 getWeather(1118370, 2019, 3, 15);//オブジェクトのwoeidプロパティの数値を最初のアーギュメントに代入。
これは東京の気温を表記する文ですが、これを前置きとして、ここで質問ですが。getWeather(1118370, この部分を getWeather(tokyo.woeid, みたいな感じに持って行きたいのですが、どこをどのようにすれば良いのでしょうか。
回答3件
あなたの回答
tips
プレビュー