-
Notifications
You must be signed in to change notification settings - Fork 1
/
Crash override.js
40 lines (19 loc) · 1.23 KB
/
Crash override.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Every budding hacker needs an alias! The Phantom Phreak, Acid Burn, Zero Cool and Crash Override are some notable examples from the film Hackers.
Your task is to create a function that, given a proper first and last name, will return the correct alias.
Two objects that return a one word name in response to the first letter of the first name and one for the first letter of the surname are already given.
If the first character of either of the names given to the function is not a letter from A - Z, you should return "Your name must start with a letter from A - Z."
Sometimes people might forget to capitalize the first letter of their name so your function should accommodate for these grammatical errors.
var firstName = {A: 'Alpha', B: 'Beta', C: 'Cache' ...}
var surname = {A: 'Analogue', B: 'Bomb', C: 'Catalyst' ...}
aliasGen('Larry', 'Brentwood') === 'Logic Bomb'
aliasGen('123abc', 'Petrovic') === 'Your name must start with a letter from A - Z.'
Happy hacking!*/
function aliasGen(a,b){
if('0123456789'.includes(a[0]) || '0123456789'.includes(b[0])){
return 'Your name must start with a letter from A - Z.'
}
a = a.toUpperCase()
b = b.toUpperCase()
return `${firstName[a[0]]} ${surname[b[0]]}`
}