commit 883efcf61c90fb08f5b4e40f3a27765bfd9335982262b3b4b166a9d810f6e3e9 Author: William Cardoso Simas Date: Wed Nov 18 09:45:53 2026 -0300 first commit diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..4044ac6 --- /dev/null +++ b/Readme.md @@ -0,0 +1,22 @@ +## Conversor de Distâncias Astronômicas + +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 distâncias astronômicas proposto como desafio no primeiro dia da imersão (13/11/2023), tendo como base o layout do conversor de moedas desenvolvido durante a aula. + +# Desafios +Os desafios foram atividades deixadas ao fim da aula para serem resolvidas. + + + +# Melhorias +As melhorias são itens incluídos no projeto e que não foram solicitados na proposta do desafio. + + diff --git a/calc.js b/calc.js new file mode 100644 index 0000000..68af6e1 --- /dev/null +++ b/calc.js @@ -0,0 +1,67 @@ +document.getElementById("form").addEventListener('submit', (e) => { + converterValores(); + e.preventDefault(); +}); + +function converterValores() { + var retorno = ""; + + var tipoConversao = document.getElementById("tipoConversao"); + 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 para converter"; + } + else if (isNaN(Number(valor))) { + retorno = "A distância deve ser um número"; + } + else { + var chave = tipoConversao.value; + valor = Number(valor); + + retorno = "Olá " + nome + '
' + if (chave == "M-A") { + var distancia = metrosParaAnosLuz(valor); + retorno += Intl.NumberFormat("pt-BR", { minimumFractionDigits: 0, maximumFractionDigits: 20 }).format(valor) + ((valor == 1) ? " metro" : " metros") + " = " + Intl.NumberFormat("pt-BR", { minimumFractionDigits: 0, maximumFractionDigits: 20 }).format(distancia) + ((distancia == 1) ? " ano-luz" : " anos-luz") + "
"; + retorno += "Sua viagem demorará " + obterTempoAnosLuz(distancia); + } + else if (chave == "A-M") { + var distancia = anosLuzParaMetros(valor); + retorno += Intl.NumberFormat("pt-BR", { minimumFractionDigits: 0, maximumFractionDigits: 20 }).format(valor) + ((valor == 1) ? " ano-luz" : " anos-luz") + " = " + Intl.NumberFormat("pt-BR", { minimumFractionDigits: 0, maximumFractionDigits: 20 }).format(distancia) + ((distancia == 1) ? " metro" : " metros") + "
"; + retorno += "Sua viagem demorará " + obterTempoAnosLuz(valor); + } + } + + document.getElementById("resultado").innerHTML = retorno; +} + +function metrosParaAnosLuz(distancia) { + return distancia / anosLuzParaMetros(1); +} + +function anosLuzParaMetros(distancia) { + return distancia * 9460528405000020; +} + +function obterTempoAnosLuz(distancia) { + var anos = Math.trunc(distancia); + var decimal = distancia - anos; + + var dias = Math.trunc(decimal * 365); + decimal = decimal * 365 - dias; + + var horas = Math.trunc(decimal * 24); + decimal = decimal * 24 - horas; + + var minutos = Math.trunc(decimal * 60); + decimal = decimal * 60 - minutos; + + var segundos = Math.trunc(decimal * 60); + decimal = decimal * 60 - segundos; + + return anos + (anos == 1 ? " ano " : " anos ") + dias + (dias == 1 ? " dia " : " dias ") + horas + (horas == 1 ? " hora " : " horas ") + minutos + (minutos == 1 ? " minuto " : " minutos ") + segundos + (segundos == 1 ? " segundo " : " segundos "); +} \ No newline at end of file diff --git a/img/Background.jpg b/img/Background.jpg new file mode 100644 index 0000000..d122ab2 Binary files /dev/null and b/img/Background.jpg differ diff --git a/img/alura-logo.svg b/img/alura-logo.svg new file mode 100644 index 0000000..1c6fb30 --- /dev/null +++ b/img/alura-logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/img/logo-imersao-aluraflix.svg b/img/logo-imersao-aluraflix.svg new file mode 100644 index 0000000..21821a0 --- /dev/null +++ b/img/logo-imersao-aluraflix.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/img/splash.png b/img/splash.png new file mode 100644 index 0000000..1fc525e Binary files /dev/null and b/img/splash.png differ diff --git a/img/telescopio.png b/img/telescopio.png new file mode 100644 index 0000000..cc971f1 Binary files /dev/null and b/img/telescopio.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..71dd168 --- /dev/null +++ b/index.html @@ -0,0 +1,53 @@ + + + + + + + + + Conversor de distâncias + + + +
+
+
+

+ Conversor de distâncias +

+ +
+ + + + +
+ +
+
+ + + + + + + + + + +
+
+ +
+ + +
+ + + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..53a6729 --- /dev/null +++ b/style.css @@ -0,0 +1,101 @@ +*{ + font-family: "Roboto Mono", monospace; + font-size: 16px; +} + +body { + text-align: center; + background-image: url("img/Background.jpg"); + background-color: #000000; + background-size: cover; + background-position: center top; + background-repeat: no-repeat; +} + +.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: 400px; + 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; + margin-bottom: 25px; +} + +button +{ + margin-top: 10px; + padding: 10px; + border: 0; + border-radius: 5px; + background-color: #cecece; + border-color: #cecece; + box-shadow: none; + font-size: 16px; +} + +.pagina +{ + max-width: 50vw; + margin-left: auto; + margin-right: auto; + background-color: rgba(0, 0, 0, 0.7); + padding: 1vw; + border-radius: 10px; + margin-top: 3vh; + height: 90vh; +} \ No newline at end of file