D39_W4-HW3


Posted by Christy on 2021-05-28

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 '找不到國家資訊'
  })









Related Posts

瀏覽器資料儲存 - Cookie、LocalStorage、SessionStorage

瀏覽器資料儲存 - Cookie、LocalStorage、SessionStorage

Print one to nine

Print one to nine

PHP 語法基礎

PHP 語法基礎


Comments