# ikeohachidi's solution

## to Bob in the Lua Track

Published at Apr 06 2020 · 0 comments
Instructions
Test suite
Solution

#### Note:

This exercise has changed since this solution was written.

Bob is a lackadaisical teenager. In conversation, his responses are very limited.

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.

Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.

## Running the tests

To run the tests, run the command busted from within the exercise directory.

## Further information

For more detailed information about the Lua track, including how to get help if you're having trouble, please visit the exercism.io Lua language page.

## Source

Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=06

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

### bob_spec.lua

local bob = require('bob')

describe('bob', function()
it('stating something', function()
local result = bob.hey('Tom-ay-to, tom-aaaah-to.')
assert.are.equals('Whatever', result)
end)

it('shouting', function ()
local result = bob.hey('WATCH OUT!')
assert.are.equals('Whoa, chill out!', result)
end)

local result = bob.hey('Does this cryogenic chamber make me look fat?')
assert.are.equals('Sure', result)
end)

it('talking forcefully', function ()
local result = bob.hey("Let's go make out behind the gym!")
assert.are.equals('Whatever', result)
end)

it('shouting numbers', function ()
local result = bob.hey('1, 2, 3 GO!')
assert.are.equals('Whoa, chill out!', result)
end)

it('shouting with special characters', function ()
local result = bob.hey('ZOMG THE %^*@#\$(*^ ZOMBIES ARE COMING!!11!!1!')
assert.are.equals('Whoa, chill out!', result)
end)

it('silence', function ()
local result = bob.hey('')
assert.are.equals('Fine, be that way.', result)
end)
end)
local bob = {}

function bob.hey(say)
local last = string.sub(say, -1)
if say == "" then
return "Fine, be that way."
elseif string.upper(say) == say and last == "!" then
return "Whoa, chill out!"
elseif last == "?" then
return "Sure"
else
return "Whatever"
end
end

return bob

### What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

• What compromises have been made?
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}