Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!