Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==========
- index.html
- ==========
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Ferramenta de conversão de moedas - FabianoVasconcelos.com</title>
- <link rel="stylesheet" href="style.css" />
- </head>
- <body>
- <h1>Câmbio Agora</h1>
- <p id="usd">Dólar Americano (USD): R$ </p>
- <p id="eur">Euro (EUR): R$ </p>
- <p id="cad">Dólar Canadense (CAD): R$ </p>
- <h2>Converter moedas</h2>
- <p>
- R$ <input type="text" name="real" size="10"/>
- <label for="moedas">equivalem a</label>
- <select id="moedas">
- <option value="usd">Dólares Americanos (USD)</option>
- <option value="eur">Euros (EUR)</option>
- <option value="can">Dólares Canadenses (CAD)</option>
- </select>
- <button type="button">Converter</button>
- </p>
- <script src='script.js'></script>
- </body>
- </html>
- =========
- script.js
- =========
- async function fetchCurrency(currency) {
- const response = await fetch(`https://economia.awesomeapi.com.br/json/${currency}-BRL`);
- const data = await response.json();
- if (currency === 'USD'){
- const currentUSD = data[0].bid.replace(".", ",");
- document.querySelector('#usd').insertAdjacentHTML('beforeend', currentUSD);
- } else if (currency === 'EUR'){
- const currentEUR = data[0].bid.replace(".", ",");
- document.querySelector('#eur').insertAdjacentHTML('beforeend', currentEUR);
- } else if (currency === 'CAD'){
- const currentCAD = data[0].bid.replace(".", ",");
- document.querySelector('#cad').insertAdjacentHTML('beforeend', currentCAD);
- }
- }
- const product = function multiplyCurrency(brl, currency) {
- return this.brl * this.currency;
- }
- currentUSD = fetchCurrency('USD');
- currentEUR = fetchCurrency('EUR');
- currentCAD = fetchCurrency('CAD');
- multiplyCurrency(4, 7);
- console.log(product);
- =========
- style.css
- =========
- html {
- background: url(img/money-bg.jpg) no-repeat center center fixed;
- -webkit-background-size: cover;
- -moz-background-size: cover;
- -o-background-size: cover;
- background-size: cover;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement