{"id":12227,"date":"2022-10-08T19:30:40","date_gmt":"2022-10-08T16:30:40","guid":{"rendered":"https:\/\/elzero.org\/?p=12227"},"modified":"2022-10-30T16:28:13","modified_gmt":"2022-10-30T13:28:13","slug":"tutorials-how-to-use-currency-api","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/tutorials-how-to-use-currency-api\/","title":{"rendered":"How To Use Currency API"},"content":{"rendered":"<h3>\u0627\u0644 Code<\/h3>\r\n\r\n<div class=\"file-name\">index.html<\/div>\r\n\r\n<script type=\"text\/plain\" class=\"language-html\">\r\n<div class=\"price\">\r\n  <span class=\"amount\">200<\/span> USD\r\n  <div class=\"egp\">Price In EGP <span><\/span><\/div>\r\n  <div class=\"sar\">Price In SAR <span><\/span><\/div>\r\n<\/div>\r\n<\/script>\r\n\r\n<div class=\"file-name\">main.js<\/div>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfetch(\"https:\/\/api.currencyfreaks.com\/latest?apikey=ADD_YOUR_KEY\")\r\n  .then((result) => {\r\n    \/\/ console.log(result);\r\n    let myData = result.json();\r\n    \/\/ console.log(myData);\r\n    return myData;\r\n  })\r\n  .then((currency) => {\r\n    let amount = document.querySelector(\".amount\");\r\n    let egpPrice = document.querySelector(\".egp span\");\r\n    let sarPrice = document.querySelector(\".sar span\");\r\n\r\n    egpPrice.innerHTML = Math.round(amount.innerHTML * currency.rates[\"EGP\"]);\r\n    sarPrice.innerHTML = Math.round(amount.innerHTML * currency.rates[\"SAR\"]);\r\n\r\n    \/\/ console.log(currency.rates);\r\n    console.log(currency.rates[\"EGP\"]);\r\n    console.log(currency.rates[\"SAR\"]);\r\n  });\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0627\u0644 Code index.html main.js<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[879],"tags":[],"class_list":["post-12227","post","type-post","status-publish","format-standard","hentry","category-front-end-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/12227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=12227"}],"version-history":[{"count":3,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/12227\/revisions"}],"predecessor-version":[{"id":12522,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/12227\/revisions\/12522"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=12227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=12227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=12227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}