Mijn vraag:
In de aanloop naar een JavaScript workshop van codeforall.io vraagt men om 59 JavaScript challenges op te lossen. De meest van de challenges zijn mij gelukt. Echter een aantal helaas niet. Waaronder deze:
<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.
You 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 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...
Start informatie:
Mijn oplossing:
Mijn code geeft deze error:
Misschien begrijp ik de vraag niet goed of mijn JavaScript skills zijn nog te n00b. Kunnen jullie mij helpen?
In de aanloop naar een JavaScript workshop van codeforall.io vraagt men om 59 JavaScript challenges op te lossen. De meest van de challenges zijn mij gelukt. Echter een aantal helaas niet. Waaronder deze:
<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.
You 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 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...
Start informatie:
JavaScript:
1
2
3
4
5
| var weeklyPass = 'darlene'; var weekDay = 'monday'; var currentPass; // 'y' is a vowel in this case // https://www.merriam-webster.com/words-at-play/why-y-is-sometimes-a-vowel-usage |
Mijn oplossing:
JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| switch (weekDay) { case 'monday': console.log(currentPass = (weeklyPass+'mnd')); break; case 'tuesday': console.log(currentPass = (weeklyPass+'tsd')); break; case 'wednesday': console.log(currentPass = (weeklyPass+'wdnsd')); break; case 'thursday': console.log(currentPass = weeklyPass+'thrsd'); break; case 'friday': console.log(currentPass = weeklyPass+'frd'); break; case 'saturday': console.log(currentPass = weeklyPass+'strd'); break; case 'sunday': console.log(currentPass = weeklyPass+'snd'); break; } console.log(currentPass); |
Mijn code geeft deze error:
Code is incorrect. Your code is producing the wrong output. The password you're printing is incorrect!
Misschien begrijp ik de vraag niet goed of mijn JavaScript skills zijn nog te n00b. Kunnen jullie mij helpen?
[ Voor 2% gewijzigd door RobIII op 29-12-2019 01:20 . Reden: Code tags toegevoegd ]