Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda