Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
if conditions in while loop

while loop with a if statement is not printing my if statement

var rest = 0
while(rest <=10) {

   rest ++;
   console.log(rest);

   if (rest == 10)
      console.log('Done!')


about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Considering what you wrote, the first step to get it working would be to fix the switch syntax and the assignment of currentPass like this:

var weekDay = 'Friday';
var currentPass = "this_week_password"; // this is the values they gave me
switch (weekDay) {
    case 'Monday':
        currentPass += 'mnd';
            break;
    case 'Tuesday':
        currentPass += 'tsd';
            break;
    case 'Wednesday':
        currentPass += 'wdnsd';
            break;
    case 'Thursday':
        currentPass += 'thrsd';
            break;    
    case 'Friday':
        currentPass += 'frd';       
            break;
    case 'Saturday':
        currentPass += 'strd';
            break;
    case 'Sunday':
        currentPass += 'snd';
            break;
    }

console.log(currentPass)

about 4 years ago · Juan Pablo Isaza Relatório

0

A simpler way to approach this would be to use Date#getDay() to get the 0-6 index of the current day within the week and store the suffixes in an array with same indexing.

Then use the day index to retrieve the associated suffix.

const suffixes = ['snd','mnd','tsd','wdnsd','thrsd','frd','strd']

const weekPass = 'ABC_';

const day = (new Date()).getDay();

const pass = weekPass + suffixes[day];

console.log('Day index =',day, ', Passs =',pass )

about 4 years ago · Juan Pablo Isaza Relatório

0

Or just this

const currentPass = "aaa",
  weekDay = new Date().getDay(), // 0-6 (sun-mon)
  dayPass = currentPass + ['snd', 'mnd', 'tsd', 'wdnsd', 'thrsd', 'frd', 'strd'][weekDay];
  
  console.log(dayPass)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda