Bob is a lackadaisical teenager. In conversation, his responses are very limited.
Bob answers 'Sure.' if you ask him a question.
He answers 'Whoa, chill out!' if you yell at him.
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.
Notes:
- Message with ALL UPPERCASES is consider yelling .
function hey(message) {
var isAllUppercase = message === message.toUpperCase();
var isYelling = message.includes("!") || isAllUppercase;
var isQuestioning = message.includes("?");
if (message.length === 0) {
return "Fine. Be that way!";
} else if (isQuestioning && isYelling) {
return "Calm down, I know what I'm doing!";
} else if (isQuestioning) {
return "Sure.";
} else if (isYelling) {
return "Whoa, chill out!";
} else {
return "Whatever.";
}
}
describe('Bob', () => {
it('stating something', () => {
const result = hey('Tom-ay-to, tom-aaaah-to.');
Test.assertEquals(result, 'Whatever.');
});
it('shouting', () => {
const result = hey('WATCH OUT!');
Test.assertEquals(result, 'Whoa, chill out!');
});
it('shouting gibberish', () => {
const result = hey('FCECDFCAAB');
Test.assertEquals(result, 'Whoa, chill out!');
});
it('asking a question', () => {
const result = hey('Does this cryogenic chamber make me look fat?');
Test.assertEquals(result, 'Sure.');
});
it('asking a numeric question', () => {
const result = hey('You are, what, like 15?');
Test.assertEquals(result, 'Sure.');
});
it('asking gibberish', () => {
const result = hey('fffbbcbeab?');
Test.assertEquals(result, 'Sure.');
});
it('using acronyms in regular speech', () => {
const result = hey("It's OK if you don't want to go to the DMV.");
Test.assertEquals(result, 'Whatever.');
});
it('forceful question', () => {
const result = hey('WHAT THE HELL WERE YOU THINKING?');
Test.assertEquals(result, 'Calm down, I know what I\'m doing!');
});
it('shouting numbers', () => {
const result = hey('1, 2, 3 GO!');
Test.assertEquals(result, 'Whoa, chill out!');
});
it('shouting with special characters', () => {
const result = hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!');
Test.assertEquals(result, 'Whoa, chill out!');
});
it('shouting with no exclamation mark', () => {
const result = hey('I HATE YOU');
Test.assertEquals(result, 'Whoa, chill out!');
});
it('silence', () => {
const result = hey('');
Test.assertEquals(result, 'Fine. Be that way!');
});
it('starting with whitespace', () => {
const result = hey(' hmmmmmmm...');
Test.assertEquals(result, 'Whatever.');
});
it('ending with whitespace', () => {
const result = hey('Okay if like my spacebar quite a bit? ');
Test.assertEquals(result, 'Sure.');
});
it('non-question ending with whitespace', () => {
const result = hey('This is a statement ending with whitespace ');
Test.assertEquals(result, 'Whatever.');
});
});