first commit

This commit is contained in:
William Cardoso Simas committed 2026-11-18 09:48:55 -03:00
commit 6379c6154b
9 files changed
+309

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
## Conversor de moedas
Projeto desenvolvido na imersão JavaScript da Alura, realizada entre os dias 13/11/2023 e 17/11/2023. Trata-se de um conversor de moedas desenvolvido no primeiro dia da imersão (13/11/2023).
# Conteúdo da aula
Durante a aula, o foco foi o uso do javascript como algoritmo, com saídas via alert().
# Desafios
Os desafios foram atividades deixadas ao fim da aula para serem resolvidas.
<ul>
<li><b>Incluir o nome da pessoa que está solicitando a conversão:</b> [Realizado]</li>
<li><b>Incluir conversão da moeda para Bitcoin:</b> [Realizado]</li>
<li><b>Adicionar outras moedas para converter:</b> [Realizado]</li>
<li><b>Criar um conversor de quilômetros para anos-luz e descobrir o tempo necessário para viajar de uma estrela para outra:</b> [Realizado]</li>
<li><b>Desenvolver um conversor de temperaturas entre Fahrenheit, Kelvin e Celsius:</b> [Realizado]</li>
</ul>
# Melhorias
As melhorias são itens incluídos no projeto e que não foram solicitados nas aulas ou desafios.
<ul>
<li>Cotações carregadas da API https://economia.awesomeapi.com.br, não sendo necessário informar a taxa de conversão manualmente.</li>
<li>Toda a interação do usuário ocorre no corpo da página, não sendo mais necessário alterar o código.</li>
<li>Alterações de css e inclusão de imagens localmente.</li>
<li>Inclusão de favicon.</li>
</ul>
+118
View File
@@ -0,0 +1,118 @@
//carrega dados de uma página externa
async function carregarPaginaExterna(url) {
var prom = new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
resolve(xhr.responseText);
}
};
xhr.open("GET", url, true);
xhr.send();
});
return await prom;
}
//converte os valores
document.getElementById("form").addEventListener('submit', (e) => {
converterValores();
e.preventDefault();
});
async function converterValores() {
var retorno = "";
var moedaSelecionada = document.getElementById("moeda");
var nome = document.getElementById("nome").value;
var valor = document.getElementById("valor").value;
if (nome == "") {
retorno = "Informe seu nome";
}
else if (valor == "") {
retorno = "Informe um valor";
}
else if (isNaN(Number(valor))) {
retorno = "Informe um número";
}
else {
var chave = moedaSelecionada.value;
var auxChave = chave.split("-");
var cotacao = await obterCotacao(chave);
var cotacaoUSD = await obterCotacao(auxChave[0] + "-USD");
var cotacaoUSDBTC = await obterCotacao("BTC-USD");
if (cotacao != null && cotacaoUSD != null && cotacaoUSDBTC != null) {
retorno = "Olá " + nome + '<br/>'
retorno += Number(valor).toFixed(2) + " " + auxChave[0] + " = " + (valor * cotacao).toFixed(2) + " " + auxChave[1] + "<br/>";
retorno += Number(valor).toFixed(2) + " " + auxChave[0] + " = " + (valor * cotacaoUSD / cotacaoUSDBTC).toFixed(7) + " BTC<br/>";
}
else {
retorno = "Não foi possível carregar os dados da moeda!";
}
}
document.getElementById("resultado").innerHTML = retorno;
}
async function obterCotacao(moeda) {
var auxChave = moeda.split("-");
var respostaTexto = await carregarPaginaExterna("https://economia.awesomeapi.com.br/last/" + moeda);
var conversao = null;
if (respostaTexto != null) {
conversao = JSON.parse(respostaTexto);
conversao = conversao[auxChave[0] + auxChave[1]].ask;
}
return conversao;
}
//carrega as moedas
async function carregarMoedas() {
var respostaTexto = await carregarPaginaExterna("https://economia.awesomeapi.com.br/xml/available");
if (respostaTexto != null) {
//Limpamdo texto
var aux = respostaTexto.search('<xml>');
respostaTexto = respostaTexto.substring(aux + 5, respostaTexto.length);
aux = respostaTexto.search('</xml>');
respostaTexto = respostaTexto.substring(0, aux);
// Carregando moedas
var tags = respostaTexto.split(">");
var moedas = [];
for (var i = 0; i < tags.length - 2; i += 2) {
var indice = tags[i].substring(1, tags[i].length);
var auxNome = tags[i + 1].split("<");
var nome = auxNome[0];
moedas[indice] = nome;
}
var objMoedas = Object.entries(moedas);
objMoedas.sort(function (a, b) {
var keyA = a[0];
var keyB = b[0];
return keyA.localeCompare(keyB);
});
//Preenchendo valores
var opcoes = "";
for (var i = 0; i < objMoedas.length; i++) {
var indice = objMoedas[i][0];
var nome = objMoedas[i][1];
var auxNomeSplit = nome.split("/");
var auxIndice = indice.split("-");
var selecionado = (indice == "BRL-USD") ? "selected" : "";
opcoes += '<option value="' + indice + '"' + selecionado + '>[' + auxIndice[0] + '] ' + auxNomeSplit[0] + ' => ' + auxNomeSplit[1] + ' [' + auxIndice[1] + ']</option>';
}
document.getElementById("moeda").innerHTML = opcoes;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

+1
View File
@@ -0,0 +1 @@
<svg viewBox="0 0 56 26" width="75" height="35" xmlns="http://www.w3.org/2000/svg"><path d="M9.1 15.887a.726.726 0 01-.36.52c-.192.124-.36.186-.53.248-.362.125-.743.25-1.146.395-.425.145-.806.29-1.146.395-.424.145-.827.27-1.21.415a3.57 3.57 0 00-.805.478 3.422 3.422 0 00-.594.706c-.17.29-.277.664-.277 1.1 0 .873.212 1.537.637 1.952.424.437 1.21.644 2.375.644 1.188 0 1.994-.228 2.42-.685.423-.457.635-1.1.635-1.93v-4.238zm-3.055-9.2c2.08 0 3.607.395 4.582 1.205.976.79 1.464 1.806 1.464 3.01v10.26c0 .415-.084.872-.232 1.37-.15.5-.446.956-.913 1.37-.445.417-1.06.77-1.845 1.04-.785.27-1.803.415-3.055.415-1.25 0-2.27-.145-3.054-.415-.784-.27-1.4-.623-1.845-1.04a3.326 3.326 0 01-.912-1.37C.085 22.035 0 21.578 0 21.163v-1.64c0-.873.233-1.683.7-2.39.467-.726 1.124-1.224 1.973-1.536.424-.145.912-.29 1.463-.477.552-.188 1.06-.375 1.57-.54.51-.167.955-.334 1.336-.48a9.26 9.26 0 01.7-.248l.382-.187c.15-.083.297-.208.446-.374.148-.165.275-.352.382-.56a1.6 1.6 0 00.17-.726v-.665a1.69 1.69 0 00-.15-.707c-.084-.25-.254-.478-.487-.685-.233-.208-.552-.374-.933-.5-.382-.123-.89-.186-1.464-.186-1.188 0-1.973.23-2.397.706-.36.416-.572.935-.614 1.516 0 .125-.106.208-.234.208l-2.587.042a.233.233 0 01-.234-.23v-.6c0-.583.107-1.123.34-1.642.234-.52.595-.955 1.082-1.33.488-.373 1.125-.684 1.888-.892.743-.25 1.655-.353 2.715-.353zm46.9 9.2a.726.726 0 01-.36.52c-.19.124-.36.186-.53.248-.36.125-.743.25-1.146.395-.425.145-.807.29-1.146.395-.425.145-.828.27-1.21.415a3.57 3.57 0 00-.806.478 3.422 3.422 0 00-.593.706c-.17.29-.276.664-.276 1.1 0 .873.21 1.537.635 1.952.424.437 1.21.644 2.376.644 1.19 0 1.995-.228 2.42-.685.423-.457.635-1.1.635-1.93v-4.238zm-3.054-9.2c2.08 0 3.607.395 4.583 1.205.975.79 1.463 1.806 1.463 3.01v10.26c0 .415-.084.872-.233 1.37-.148.5-.445.956-.912 1.37-.445.417-1.06.77-1.845 1.04-.784.27-1.803.415-3.054.415-1.25 0-2.27-.145-3.054-.415-.784-.27-1.4-.623-1.845-1.04a3.325 3.325 0 01-.91-1.37c-.15-.498-.235-.955-.235-1.37v-1.64c0-.873.234-1.683.7-2.39.467-.726 1.125-1.224 1.973-1.536.424-.145.912-.29 1.464-.477.55-.188 1.06-.375 1.57-.54.51-.167.954-.334 1.336-.48a9.26 9.26 0 01.7-.248l.382-.187c.148-.083.297-.208.445-.374a2.54 2.54 0 00.382-.56 1.6 1.6 0 00.17-.726v-.665a1.69 1.69 0 00-.15-.707c-.084-.25-.253-.478-.487-.685-.233-.208-.55-.374-.933-.5-.382-.123-.89-.186-1.464-.186-1.188 0-1.972.23-2.397.706-.36.416-.572.935-.615 1.516 0 .125-.105.208-.232.208H44.12a.233.233 0 01-.232-.228v-.603c0-.58.106-1.12.34-1.64.233-.518.593-.955 1.08-1.328.49-.374 1.125-.686 1.89-.893.72-.21 1.632-.313 2.693-.313zm-9.1.083h1.698c.148 0 .254.146.212.29l-.573 2.16c-.02.105-.127.167-.212.167h-1.188c-.636 0-1.145.083-1.548.25-.383.165-.7.352-.913.58-.212.23-.34.457-.403.686a2.74 2.74 0 00-.085.685v13.354a.233.233 0 01-.235.228H35a.233.233 0 01-.233-.228V10.985c0-.248.042-.622.148-1.1.085-.477.34-.934.743-1.412.403-.457.997-.872 1.803-1.204.807-.334 1.91-.5 3.33-.5zm-8.57 13.935v.623c0 .27-.04.644-.147 1.122-.085.456-.34.934-.743 1.39-.403.458-.997.873-1.803 1.205-.806.333-1.91.5-3.33.5-1.42 0-2.524-.167-3.33-.5-.806-.332-1.4-.726-1.803-1.204-.403-.456-.658-.934-.743-1.41-.084-.48-.147-.832-.147-1.102V7.352c0-.125.106-.23.233-.23h2.524c.128 0 .234.105.234.23v13.083c0 .436.063.748.127.997.065.25.192.498.383.706.19.228.488.415.89.56.382.146.913.23 1.57.23.68 0 1.23-.084 1.634-.23.403-.145.7-.332.912-.54.21-.207.36-.435.423-.685.064-.25.15-.456.15-1.06V7.332c0-.124.105-.228.232-.228h2.524c.126 0 .232.104.232.23v13.373h-.02zM14.85.105h2.525c.127 0 .233.103.233.227v24.734a.233.233 0 01-.233.23H14.85a.233.233 0 01-.233-.23V.332c.02-.124.106-.228.233-.228z" fill="#fff" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

+1
View File
@@ -0,0 +1 @@
<svg width="473" height="95" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><path d="M14.407 26.728c1.053 0 1.815-.293 2.287-.878.471-.585.707-1.282.707-2.092 0-.45-.06-.866-.181-1.249a2.716 2.716 0 00-.576-1.012 2.773 2.773 0 00-.92-.607c-.374-.158-.812-.237-1.317-.237-.504 0-.943.08-1.315.237-.373.157-.68.36-.921.607a2.53 2.53 0 00-.56 1.03 4.57 4.57 0 00-.164 1.231c0 .81.23 1.507.69 2.092.461.585 1.218.878 2.27.878zm14.243 43.53v-3.61H16.513V33.747H0v3.61h12.598v29.29H0v3.611h28.65zm11.151 0l.033-27.84c.176-.674.395-1.349.658-2.024a6.329 6.329 0 011.086-1.822c.482-.585 1.102-1.052 1.858-1.4.757-.35 1.705-.535 2.845-.557 1.031-.023 1.88.135 2.55.472.668.338 1.2.788 1.595 1.35.395.585.669 1.254.822 2.008.154.753.23 1.513.23 2.278l.033 27.535h3.717l.033-27.502-.004-.16-.012-.143a2.53 2.53 0 01-.017-.304c.154-.675.373-1.339.658-1.991a6.186 6.186 0 011.152-1.755c.504-.517 1.129-.939 1.875-1.265.745-.326 1.666-.5 2.763-.523 1.074-.023 1.951.152 2.631.523.68.371 1.217.86 1.612 1.468a5.96 5.96 0 01.806 2.126c.142.787.214 1.574.214 2.362l.032 27.164h3.717l.033-27.13c0-1.395-.142-2.706-.427-3.932-.285-1.226-.757-2.3-1.415-3.222-.592-.878-1.414-1.58-2.467-2.11-1.052-.528-2.324-.792-3.815-.792-1.031 0-1.969.135-2.813.405-.844.27-1.606.63-2.286 1.08a8.286 8.286 0 00-1.677 1.484 9.491 9.491 0 00-1.218 1.789 8.613 8.613 0 00-.855-1.823 5.982 5.982 0 00-1.316-1.484c-.592-.45-1.293-.805-2.105-1.063-.811-.259-1.743-.388-2.796-.388-1.951.022-3.558.466-4.819 1.333-1.26.866-2.242 2.019-2.944 3.458l-.131-4.116h-3.52v36.511h3.684zm55.327.675c2.96 0 5.56-.596 7.796-1.788 2.237-1.192 4.035-2.756 5.395-4.69l-2.5-1.958c-1.272 1.62-2.796 2.857-4.572 3.712-1.777.855-3.761 1.282-5.954 1.282-1.908-.022-3.64-.416-5.197-1.18a12.264 12.264 0 01-4.013-3.139c-1.097-1.26-1.957-2.722-2.582-4.387-.625-1.665-.982-3.464-1.07-5.399v-1.114h26.644V49.81c0-2.317-.323-4.494-.97-6.53-.647-2.036-1.584-3.818-2.812-5.348-1.25-1.507-2.79-2.694-4.622-3.56-1.831-.866-3.92-1.3-6.266-1.3-2.237 0-4.315.473-6.234 1.418a15.655 15.655 0 00-5.016 3.914c-1.447 1.665-2.582 3.622-3.404 5.872-.823 2.25-1.234 4.68-1.234 7.289v1.45c0 2.453.406 4.764 1.217 6.935.812 2.171 1.952 4.078 3.421 5.72 1.447 1.62 3.19 2.902 5.23 3.847 2.04.945 4.287 1.417 6.743 1.417zm10.033-22.136H82.629c.22-1.755.658-3.38 1.316-4.876.657-1.496 1.502-2.796 2.532-3.898a11.215 11.215 0 013.52-2.548c1.338-.618 2.807-.928 4.408-.928 1.688 0 3.19.332 4.506.996a10.454 10.454 0 013.355 2.649c.9 1.102 1.607 2.384 2.122 3.847.515 1.462.773 2.924.773 4.387v.37zm24.769 21.461l-.066-23.385c.439-1.664 1.07-3.11 1.892-4.336.822-1.226 1.792-2.244 2.91-3.054a12.104 12.104 0 013.931-1.839c1.459-.394 3.021-.59 4.688-.59.965 0 1.908.056 2.829.168.92.113 1.83.27 2.73.473l.526-3.915c-.68-.225-1.519-.4-2.516-.523a23.909 23.909 0 00-2.944-.185c-3.224-.023-6.025.663-8.405 2.058-2.379 1.395-4.26 3.34-5.64 5.838l-.034-1.62-.23-5.601h-3.75v36.511h4.079zm45.623.675a21.53 21.53 0 005.494-.708c1.798-.473 3.377-1.204 4.736-2.194a9.99 9.99 0 002.73-3.087c.702-1.226 1.053-2.627 1.053-4.202 0-1.664-.367-3.087-1.102-4.268-.734-1.181-1.716-2.188-2.944-3.02-1.25-.833-2.697-1.519-4.342-2.059a55.99 55.99 0 00-5.164-1.417 54.503 54.503 0 01-4.03-.996c-1.282-.37-2.384-.838-3.305-1.4-.921-.518-1.623-1.164-2.106-1.94-.482-.777-.723-1.693-.723-2.75 0-1.058.274-1.986.822-2.785a6.648 6.648 0 012.138-1.974c.877-.54 1.88-.939 3.01-1.198a15.64 15.64 0 013.503-.388c1.272 0 2.506.169 3.7.506 1.196.338 2.265.822 3.208 1.452a7.901 7.901 0 012.253 2.328c.581.922.883 1.968.905 3.138h3.98c-.066-1.732-.477-3.273-1.234-4.623a11.042 11.042 0 00-3.01-3.442c-1.25-.922-2.713-1.625-4.39-2.109-1.678-.484-3.482-.725-5.412-.725-1.71 0-3.371.225-4.983.675-1.612.45-3.02 1.08-4.227 1.89-1.272.877-2.286 1.934-3.043 3.171-.756 1.238-1.135 2.644-1.135 4.218 0 1.665.379 3.077 1.135 4.235a9.155 9.155 0 002.977 2.852 20.863 20.863 0 004.243 1.923 47.63 47.63 0 005 1.316 39.32 39.32 0 014.178 1.148c1.337.45 2.478.99 3.42 1.62.856.562 1.525 1.242 2.007 2.04.483.8.724 1.728.724 2.785 0 .855-.181 1.63-.543 2.328a5.926 5.926 0 01-1.53 1.856c-1.008.788-2.203 1.378-3.585 1.772-1.381.394-2.85.59-4.408.59-1.184 0-2.395-.118-3.634-.354a11.029 11.029 0 01-3.405-1.232 8.4 8.4 0 01-2.615-2.311c-.713-.956-1.135-2.154-1.266-3.594h-3.947c.065 1.665.487 3.172 1.266 4.522.778 1.35 1.847 2.497 3.207 3.442 1.316.922 2.873 1.648 4.67 2.176 1.8.529 3.707.793 5.724.793zm31.94-44.24c.044-.809.269-1.523.674-2.142.406-.619.927-1.018 1.563-1.198.439-.202.894-.32 1.365-.354.472-.034.981.005 1.53.118a5.228 5.228 0 011.727.692 78.56 78.56 0 001.792 1.096c.592.405 1.212.76 1.859 1.063.647.304 1.398.456 2.253.456.92 0 1.76-.186 2.516-.557a5.627 5.627 0 001.925-1.535 6.336 6.336 0 001.266-2.177 8.564 8.564 0 00.477-2.649L223.874 19a6.16 6.16 0 01-.329 1.586 4.43 4.43 0 01-.69 1.282c-.307.383-.68.686-1.119.911a3.196 3.196 0 01-1.48.338c-.877 0-1.672-.191-2.385-.574a21.342 21.342 0 01-2.089-1.282 29.794 29.794 0 00-2.17-1.266c-.746-.393-1.58-.59-2.5-.59-.943 0-1.7Line truncated

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

+52
View File
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="img/Conversao_1.png" type="image/x-icon">
<title>Conversor de moedas</title>
</head>
<body onload="carregarMoedas()">
<header>
<div class="container">
<h1 class="page-title">
Conversor de moedas
</h1>
<img src="img/logo-imersao-aluraflix.svg" class="page-logo" alt="Logo da página">
</div>
<a href="https://alura.com.br/" target="_blank">
<img src="img/alura-logo.svg" alt="" class="alura-logo">
<img src="img/Conversao_1.png" style="height: 150px;">
</a>
</header>
<section>
<form id="form">
<label for="nome">Informe seu nome</label>
<input type="text" name="nome" id="nome">
<label for="moeda">Selecione as moedas</label>
<select name="moeda" id="moeda"></select>
<label for="valor">Valor a converter</label>
<input type="text" name="valor" id="valor">
<button>Converter</button>
</form>
</section>
<div id="resultado"></div>
<footer>
Cotações provenientes da API <a href="https://economia.awesomeapi.com.br">https://economia.awesomeapi.com.br</a>
</footer>
<script src="calc.js">
</script>
</body>
</html>
+110
View File
@@ -0,0 +1,110 @@
*{
font-family: "Roboto Mono", monospace;
font-size: 16px;
}
body {
text-align: center;
background-image: url("img/Background.png");
background-color: #000000;
background-size: cover;
background-position: center top;
background-repeat: no-repeat;
/*height: 100vh;*/
}
.container {
text-align: center;
padding: 20px;
}
.page-title {
color: #ffffff;
margin: 0 0 5px;
}
.page-subtitle {
color: #ffffff;
margin-top: 5px;
}
.page-logo {
width: 200px;
}
.alura-logo {
width: 40px;
position: absolute;
top: 10px;
right: 10px;
}
body>img {
margin: 0 10px;
}
img {
max-height: 250px;
}
form{
margin-left: auto;
margin-right: auto;
display: flex;
flex-direction: column;
max-width: 600px;
text-align: center;
}
form label{
color:white;
margin-top: 10px;
}
form input{
text-align: center;
}
select{
text-align: center;
}
#resultado
{
color: white;
margin-top: 10px;
}
button
{
margin-top: 10px;
padding: 10px;
border: 0;
border-radius: 5px;
background-color: cyan;
border-color: darkcyan;
box-shadow: none;
font-size: 16px;
}
.resultado
{
flex-grow: 1;
color:white;
margin-bottom: 25px;
}
footer
{
background-color: #000000;
color: #ffffff;
display: block;
position: fixed;
bottom: 0;
width: 101%;
left: -1%;
}
a{
color:#ffffff;
}