-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_16.js
66 lines (50 loc) · 1.98 KB
/
day_16.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Ask the Bob
// Instructions
// Bob is a lackadaisical teenager. In conversation, his responses are very limited.
// Bob answers 'Sure.' if you ask him a question, such as "How are you?".
// He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
// He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
// He says 'Fine. Be that way!' if you address him without actually saying anything.
// He answers 'Whatever.' to anything else.
// Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
const isUpper = (string) => {
return !/[a-z]/.test(string) && /[A-Z]/.test(string)
}
function hey(message) {
// Code here
let pureLetterString = ""
message.split("").forEach(character => {
if(/[a-zA-Z]/.test(character)){
pureLetterString += character
}
})
console.log(pureLetterString);
if(isUpper(pureLetterString) && message.trim().charAt(message.length-1) === '?'){
return "Calm down, I know what I'm doing!"
}
else if(isUpper(pureLetterString)){
return "Whoa, chill out!"
}
else if(message.trim().charAt(message.length-1) === '?'){
return "Sure."
}
else if(message === ""){
return "Fine. Be that way!"
}
return "Whatever."
}
function hey1(message) {
let pureLetterString = ""
message.split("").forEach(character => {
if(/[a-zA-Z]/.test(character)){
pureLetterString += character
}
})
console.log(pureLetterString);
if(pureLetterString == pureLetterString.toUpperCase() && message.slice(-1) === '?') return "Calm down, I know what I'm doing!";
else if(pureLetterString == pureLetterString.toUpperCase()) return 'Whoa, chill out!';
else if(message.slice(-1) == '?') return "Sure";
else if(message === "") return 'Fine. Be that way!';
return 'Whatever.'
}
console.log(hey('HASDFASDF ASDF23423 ASDF ?'));