Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Timothy Van Cauwenberge
Timothy Van Cauwenberge
8,958 Points

Help creating a chatbot

I'm working on creating a chatbot in java. I need it to return "Tell em more about father(or mother)" if the user says something like "I hate my mother" or "I hate my father". So I think I would need to find a way to find the string "mother" inside the user's input to trigger the "tell me more about your mother" string from the chatbot. Please help.

Timothy Van Cauwenberge
Timothy Van Cauwenberge
8,958 Points

I figured out I should use the .contains() method on the user's input. But idk how to make it so if the user puts in "Mother"(capital M) instead of "mother" it'll still accept "Mother" like it would "mother"

1 Answer

I'm not very familiar with Java (I'm new, let's put it that way), but I'm sure you can convert the input to lowercase somehow. I would search the Java documentation (look it up).

If there's a function that returns the lowercased version of a string, you can use that. I'm assuming there's a .toLowerCase() function. Notice it might cause an error, since you should find the function that lowercases a string.

If .toLowerCase() were a function on strings, this would probably work:

// Returns true if "testString" variable has the sub string "mother", or else false

I hope this helps :grin:

Good luck coding :sparkles: :+1: :sparkles:

:dizzy: ~Alex :dizzy: