-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbob.js
More file actions
23 lines (18 loc) · 726 Bytes
/
Copy pathbob.js
File metadata and controls
23 lines (18 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
// This is only a SKELETON file for the 'Bob' exercise. It's been provided as a
// convenience to get you started writing code faster.
//
const HAS_YELL_POSSIBILITY = /[A-Z]/;
const YELL_EXPRESSION = /^[^a-z]+$/g;
const YELL_WITH_QUESITON_EXPRESSION = /^[^(a-z?)]+\?$/g;
const NO_EXPRESSION = /^$|^[\s]+$/g;
export const hey = message => {
if (message.match(NO_EXPRESSION)) return "Fine. Be that way!";
if (message.match(HAS_YELL_POSSIBILITY)) {
if (message.match(YELL_WITH_QUESITON_EXPRESSION))
return "Calm down, I know what I'm doing!";
if (message.match(YELL_EXPRESSION)) return "Whoa, chill out!";
}
if (message.trim().charAt(message.trim().length - 1) === "?") return "Sure.";
return "Whatever.";
};