Advertisement
fvasconcelos

Conversor de moedas

Nov 18th, 2020
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ==========
  2. index.html
  3. ==========
  4.  
  5. <!DOCTYPE html>
  6. <html lang="en">
  7. <head>
  8.     <meta charset="UTF-8">
  9.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  10.     <title>Ferramenta de conversão de moedas - FabianoVasconcelos.com</title>
  11.     <link rel="stylesheet" href="style.css" />
  12. </head>
  13. <body>
  14.     <h1>Câmbio Agora</h1>
  15.     <p id="usd">Dólar Americano (USD): R$ </p>
  16.     <p id="eur">Euro (EUR): R$ </p>
  17.     <p id="cad">Dólar Canadense (CAD): R$ </p>
  18.  
  19.     <h2>Converter moedas</h2>
  20.     <p>
  21.         R$ <input type="text" name="real" size="10"/>
  22.         <label for="moedas">equivalem a</label>
  23.         <select id="moedas">
  24.             <option value="usd">Dólares Americanos (USD)</option>
  25.             <option value="eur">Euros (EUR)</option>
  26.             <option value="can">Dólares Canadenses (CAD)</option>
  27.         </select>
  28.         <button type="button">Converter</button>
  29.     </p>
  30.     <script src='script.js'></script>
  31. </body>
  32. </html>
  33.  
  34. =========
  35. script.js
  36. =========
  37.  
  38. async function fetchCurrency(currency) {
  39.   const response = await fetch(`https://economia.awesomeapi.com.br/json/${currency}-BRL`);
  40.   const data = await response.json();
  41.  
  42.   if (currency === 'USD'){
  43.       const currentUSD = data[0].bid.replace(".", ",");
  44.       document.querySelector('#usd').insertAdjacentHTML('beforeend', currentUSD);
  45.   } else if (currency === 'EUR'){
  46.       const currentEUR = data[0].bid.replace(".", ",");
  47.       document.querySelector('#eur').insertAdjacentHTML('beforeend', currentEUR);
  48.   } else if (currency === 'CAD'){
  49.       const currentCAD = data[0].bid.replace(".", ",");
  50.       document.querySelector('#cad').insertAdjacentHTML('beforeend', currentCAD);
  51.   }
  52. }
  53.  
  54. const product = function multiplyCurrency(brl, currency) {
  55.   return this.brl * this.currency;
  56. }
  57.  
  58. currentUSD = fetchCurrency('USD');
  59. currentEUR = fetchCurrency('EUR');
  60. currentCAD = fetchCurrency('CAD');
  61.  
  62. multiplyCurrency(4, 7);
  63. console.log(product);
  64.  
  65. =========
  66. style.css
  67. =========
  68.  
  69. html {
  70.     background: url(img/money-bg.jpg) no-repeat center center fixed;
  71.     -webkit-background-size: cover;
  72.     -moz-background-size: cover;
  73.     -o-background-size: cover;
  74.     background-size: cover;
  75.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement