W4 HW3
- 解題想法:我真的盡力了,寫了一個多小時,終於好像把東西印出來了,可是有字母大小寫跟搜尋國全名的問題
const request = require('request');
const process = require('process')
const name = process.argv[2]
request('https://restcountries.eu/rest/v2/all?fields=name;capital;currencies;callingCodes',
function (error, response, body) {
const str = JSON.parse(body)
for (let i = 0; i < str.length; i++) {
if(name === str[i].name) {
console.log('國家:', str[i].name)
console.log('首都:', str[i].capital)
console.log('貨幣:', str[i].currencies[0].code)
console.log('國碼:', str[i].callingCodes[0])
}
}
return '找不到國家資訊'
})