Skip to content
This repository has been archived by the owner on May 15, 2022. It is now read-only.

Commit

Permalink
Finalizado Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcon83 committed Mar 16, 2021
1 parent e53a2c9 commit 96a5d4a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Dia 34 - JS - Datas/D34E1 - Datas.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

let input, display;
let data = new Date();
let agora = `O dia é ${data.getDate() + 1}/${pad(data.getMonth() + 1, 2)}/${data.getFullYear()} - ${diaDaSemana(data.getDay())}`
let agora = `O dia é ${data.getDate() + 1}/${ad0s(data.getMonth() + 1, 2)}/${data.getFullYear()} - ${diaDaSemana(data.getDay())}`

// Atribui valores as variáveis após finalizar o carregamento da página
window.onload = () => {
Expand All @@ -38,21 +38,22 @@
};


function mostrar() {
function atualizar() {
display.value = escreverData(input.value)
}


// Pega o input, divide a string, reformata e retorona ela
function escreverData(dataIn) {
let dataPart = dataIn.split("/");
return `${dataPart[0]} de ${mes(dataPart[1])} de ${dataPart[2]}`;
}

// Adiciona 0s
function pad(num, size) {
function ad0s(num, tamanho) {
num = num.toString();
while (num.length < size) num = "0" + num;
while (num.length < tamanho) {
num = "0" + num;
}
return num;
}

Expand Down Expand Up @@ -123,7 +124,7 @@
<h1 id="dia-de-hoje"></h1>
<hr>
<input id="input" class="sem-foco" name="caixaInput" type="text" placeholder="DD/MM/AAAA">
<button onclick="mostrar()">Mostrar</button>
<button onclick="atualizar()">Mostrar</button>
<input id="display" class="sem-foco" name="caixaInput" type="text" placeholder="Resultado aqui." readonly>
<hr>

Expand Down

0 comments on commit 96a5d4a

Please sign in to comment.