Switch Statement | How to create a password

Hi there,

The code below does not seem to be good enough for the following challenge:

Having got the value of the weekly password stored in weeklyPass, update the value of currentPass depending on the day of the week we are in. To know which day of the week it is simply access weekDay.

Remember that updating the password is appending the letters corresponding to the consonants present in the name of the current day of the week.

There are many ways of cracking this problem, but Elliot and the guys specifically asked for you to use a switch statement…

var weeklyPass = 'darlene';
var weekDay = 'monday';
var currentPass;


    switch (weekDay) {
            
        case 'monday':
        console.log (weeklyPass+'mnd');
            break;
            
        case 'tuesday':
        console.log(weeklyPass+'tsd');
            break;
            
        case 'wednesday':
        console.log (weeklyPass+'wsdnsd');
            break;
            
        case 'thursday':
        console.log (weeklyPass+'thrsd');
            break;
            
        case 'friday':
        console.log (weeklyPass+'frd');
            break;
            
        case 'saturday':
        console.log (weeklyPass+'strd');
            break;
            
        case 'sunday':
        console.log (weeklyPass+'snd');
            break;
            
        default:
            console.log('');
}

The error that I get is only that it it not up to the required standards, but I cannot figure out how I could do things differently.

Thanks
Diana

As far as I can see, it’s not updating the currentPass, just logging to the console … Could that be the reason?

It could be . How do I do that?

It could be . How do I do that?

Instead of the console.logs you write:

currentPass = weeklyPass+'mnd';

etc.

At the bottom you can test the result with:
console.log(currentPass);

I have tried to do something similar but that would be valid for any weekDay possible, by making the variable link directly to the switch statement, but it didnt work.

I am not sure I understand you correctly.

If I try the following and console.log I get the result on the right:
image

Do you run this through some automated tests?
What result are you expecting and what do you get instead?

The results seem to be good but this does not seem to be the way I need to write it.
Is there any other way that I could get this result still using a switch statement?

what are the requirements? without those it is difficult to say, other than trying thousand different ways

I’m having the same problem with a similar switch statement.
Someone knows how to solve this example shared in here!?

#imanoobcoder

Heyy… did you figure it out? I am stuck on this as well

Heyy… did you figure it out? I am stuck on this as well

1 Like