Jump to content

Recommended Posts

Posted

Boa tarde,

 

Estou a criar este tópico no sentido de pedir ajuda para uma code challenge que estou a fazer. Já passei horas à volta disto e portanto queria-vos pedir feedback sobre o meu código e o que eventualmente eu possa melhorar.

 

Antes de mais fico desde já agradecido pelo vosso tempo e disponibilidade.

 

O enunciado é o seguinte:

Citação

 

Hacking Task 1

Now that you're no longer a total JavaScript n00bster, you can help Elliott and the fSociety crew with a little pet project. Security is paramount to this group of anarchist rebels. And someone has to make sure that their hideout is not compromised.

The password to enter the Arcade has to be kept secure, and it changes every day. The first seven characters change every week, while the last ones are updated every day. The daily password is generated by appending to the weekly password the consonants of the day of the week we are in.

Your job is to create a piece of software that automatically updates the password every time a day goes by and print it.

 

Instructions

Having got the value of the weekly password stored in weeklyPass, update and print to the console 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...

 

 

O meu Código:

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

console.log(weekDay);

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

console.log(currentPass);

// 'y' is a vowel in this case
// https://www.merriam-webster.com/words-at-play/why-y-is-sometimes-a-vowel-usage

 

Posted

var weeklyPass	= 'darlene';
var weekDay		= 'saturday';

var currentPass = weeklyPass;

console.log(weekDay);

switch(weekDay){
	case 'monday':
	case 'tuesday':
	case 'wednesday':
	case 'thursday':
	case 'friday':
	case 'saturday':
	case 'sunday':
		
		currentPass += weekDay.replace(/[aeiouy]/gi, '');
	break;

	default:
		console.log('Error!');
}

console.log(currentPass);

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.