Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of rootulp

rootulp's solution

to Bob in the CoffeeScript 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 says 'Fine. Be that way!' if you address him without actually saying anything.

He answers 'Whatever.' to anything else.

Refer to the Exercism CoffeScript page for getting started with CoffeeScript.

In order to run the test, you can run the test file from the exercise directory:

jasmine-node --coffee .


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 = require "./bob"
describe "Bob", ->
  bob = new Bob()
  it "stating something", ->
    result = bob.hey "Tom-ay-to, tom-aaaah-to."
    expect(result).toEqual "Whatever."

  xit "shouting", ->
    result = bob.hey "WATCH OUT!"
    expect(result).toEqual "Whoa, chill out!"

  xit "asking a question", ->
    result = bob.hey "Does this cryogenic chamber make me look fat?"
    expect(result).toEqual "Sure."

  xit "talking forcefully", ->
    result = bob.hey "Let's go make out behind the gym!"
    expect(result).toEqual "Whatever."

  xit "using acronyms in regular speech", ->
    result = bob.hey "It's OK if you don't want to go to the DMV."
    expect(result).toEqual "Whatever."

  xit "forceful questions", ->
    result = bob.hey "WHAT THE HELL WERE YOU THINKING?"
    expect(result).toEqual "Whoa, chill out!"

  xit "shouting numbers", ->
    result = bob.hey "1, 2, 3 GO!"
    expect(result).toEqual "Whoa, chill out!"

  xit "only number", ->
    result = bob.hey "1, 2, 3"
    expect(result).toEqual "Whatever."

  xit "shouting with special characters", ->
    result = bob.hey "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    expect(result).toEqual "Whoa, chill out!"

  xit "shouting with no exclamation mark", ->
    result = bob.hey "I HATE YOU"
    expect(result).toEqual "Whoa, chill out!"

  xit "statement containing question mark", ->
    result = bob.hey "Ending with a ? means a question."
    expect(result).toEqual "Whatever."

  xit "prattling on", ->
    result = bob.hey "Wait! Hang on.  Are you going to be OK?"
    expect(result).toEqual "Sure."

  xit "silence", ->
    result = bob.hey ""
    expect(result).toEqual "Fine. Be that way!"

  xit "prolonged silence", ->
    result = bob.hey "   "
    expect(result).toEqual "Fine. Be that way!"
class Bob
  hey: (input) ->
    if !input.trim()
      "Fine. Be that way!"
    else if input is input.toUpperCase() and input isnt input.toLowerCase()
      'Whoa, chill out!'
    else if input.slice(-1) is '?'

module.exports = Bob

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?