Hello.
Trying to solved a challenge from Exercism.io
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.
Bob’s conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
how would you approch it?
My first intuition was to look for the end special character with the strings.Contains()
, since, for my understanding;
if you yell a question, it ends in “!”
If you ask a question if ends in “?”
if you Yell a question if ends with “!?”
And if you address him without saying anything and example could be “bob” (Not sure about this one), you could check for bob in the word.
At last, a default answer to anything that does match any of the above.
I created a switch statement, but i ran into a problem if question ends in “!?” the switch statement will return true at first statement that is “!”
Also other problems like, if I ask a question with bob in it like “Bob have you taken out the trash?” It might return true at bob, instead of “?” (If Bob is checked for first that is)
Then I thought about splitting the string and check for the last element in the array, to see if it is equals to “!”, “?”… and so on.
But since it have to be correct punctuation, a sentence will end in “Example?” and not “Example ?”
I have been looking through the standard libary, but so far I failed to find a method that would be able to help me solved this problem, so I turn to you.
How would you go on about solving this problem?
I am not so much interested in the finished code, as I am in the steps it takes to solved a problem, you have no idea how to start.
Hope I make a bit of sense.