Skip to content

Instantly share code, notes, and snippets.

@ericdouglas
Last active December 6, 2020 03:58
Show Gist options
  • Save ericdouglas/8781354 to your computer and use it in GitHub Desktop.
Save ericdouglas/8781354 to your computer and use it in GitHub Desktop.
Resolução do Exercício 03 do Capítulo 03 - JavaScript Eloquente
var
tamanho = 8,
tijolo1 = "#",
tijolo2 = " ",
parede1 = "",
parede2 = " ",
auxiliar = true,
contador = 1;
while ( contador < tamanho ) {
if ( auxiliar ) {
parede1 += tijolo1;
parede2 += tijolo1;
contador += 1;
auxiliar = !auxiliar;
} else {
parede1 += tijolo2;
parede2 += tijolo2;
contador += 1;
auxiliar = !auxiliar;
}
}
while ( contador > 1 ) {
if ( !auxiliar ) {
console.log( parede1 );
contador -= 1;
auxiliar = ! auxiliar;
}
console.log( parede2 );
contador -= 1;
auxiliar = ! auxiliar;
}
@icaro911
Copy link

for (var i = 1; i <= 8; i++) {
if (i % 3 == 0){
console.log("# # # #")}
else if ((i % 2 == 0) && (i % 3 == 0,33)){
console.log(" # # # #") }
}

@oastro
Copy link

oastro commented Aug 4, 2020

var tamanho = 8
var xadrez;

for( y = 0; y < tamanho; y++){
 xadrez = "";
  for( x = 0; x < tamanho; x++){
    if(y % 2){
      xadrez += " ";
      xadrez += "#"
    }else{
      xadrez += "#";
      xadrez += " ";
    }
  }
  console.log(xadrez);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment