🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of JaeHyoLee

JaeHyoLee's solution

to Bob in the Lua Track

Published at Jul 13 2018 · 0 comments
Test suite


This solution was written on an old version of Exercism. The tests below might not correspond to the solution code, and the exercise may have changed since this code was written.

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.

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.


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.


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)

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

  it('asking a question', function ()
    local result = bob.hey('Does this cryogenic chamber make me look fat?')
    assert.are.equals('Sure', result)

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

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

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

  it('silence', function ()
    local result = bob.hey('')
    assert.are.equals('Fine, be that way.', result)
local function isUpperCase(source)
  return source:upper() == source

return {
  hey = function(source)
    if source == '' then
      return 'Fine, be that way.'
    elseif source:find('?') then
      return 'Sure'
    elseif isUpperCase(source) then
      return 'Whoa, chill out!'
      return 'Whatever'

Community comments

Find this solution interesting? Ask the author a question to learn more.

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?
  • Are there new concepts here that you could read more about to improve your understanding?