Skip to content

Commit

Permalink
update repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ycanas committed Mar 7, 2024
1 parent 594e812 commit c8f9e32
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ const buttonBinary = document.getElementById('buttonBinary');
const buttonText = document.getElementById('buttonText');


buttonBinary.onclick = function(){
buttonBinary.onclick = function() {
const divOutput = document.getElementById('divOutput');
const input = document.getElementById('inputText').value;
let output = "";

if(input == ''){
if (input == '') {
divOutput.innerHTML = "";
document.getElementById('divOutput').className = "";
return;
}

for(let i = 0; i < input.length; i++){
for (let i = 0; i < input.length; i++) {
let binary = input.charCodeAt(i).toString(2).toString();
output += Array(8 - binary.length + 1).join('0') + binary + " ";
}
Expand All @@ -24,26 +24,26 @@ buttonBinary.onclick = function(){
}


buttonText.onclick = function(){
buttonText.onclick = function() {
const divOutput = document.getElementById('divOutput');
const input = document.getElementById('inputText').value.split(' ');
let output = "";

if(input == ''){
if (input == '') {
divOutput.innerHTML = "";
document.getElementById('divOutput').className = "";
return;
}

for(let i = 0; i < input.length; i++){
if(isNaN(parseInt(input[0], 2))){
for (let i = 0; i < input.length; i++) {
if (isNaN(parseInt(input[0], 2))) {
document.getElementById('inputText').value = "";
divOutput.className = "w-50 mt-1 alert alert-danger mx-auto";
divOutput.innerHTML = "Tipo de texto inválido";
divOutput.className = "w-75 mt-1 alert alert-danger mx-auto";
divOutput.innerHTML = "Tipo de texto no válido";
return;
}

if(parseInt(input[0], 2) < 32){
if (parseInt(input[0], 2) < 32) {
divOutput.innerHTML = "";
divOutput.className = "";
document.getElementById('inputText').value = "";
Expand All @@ -54,6 +54,6 @@ buttonText.onclick = function(){
}

document.getElementById('inputText').value = "";
divOutput.className = "w-50 mt-1 alert alert-success mx-auto";
divOutput.className = "w-75 mt-1 alert alert-success mx-auto";
divOutput.innerHTML = `${output.trim()}`;
}

0 comments on commit c8f9e32

Please sign in to comment.