This is probably going to be for elementary for most but I'm new to Swift and trying to do a chatbot in Xcode where response is dependent on keywords and without the same response for 5 interactions. I want to increase the answer under each category each time and reset it after the 5 responses to start over. I have tried numerous ways and keep getting errors. Here is my code below for the questionanswer page. Can anyone assist?
Patricia Kennison kennisonp6616@connect.durhamtech.edu
5:11 PM (31 minutes ago)
to me
struct QuestionAnswerer {
/// Creates a String in response to another String.
func responseTo(question: String) -> String {
let lowerQuestion = question.lowercased()
//class Counter {
//var count = 0
//func increment () {
//count += 1
// }
//}
//let counter = Counter()
//func increment (by amount: Int) {
//count += amount
//}
if lowerQuestion.hasPrefix("hello") {
return "hello there!"
} else if lowerQuestion == "where are the cookies?" {
return "I ate them!"
} else if lowerQuestion.hasPrefix("where") {
return "To the beach or mountains!"
} else if lowerQuestion.contains("stressed") {
let stressedNumber = question.count % 3
switch stressedNumber {
case 0:
return "Please take a deep breath and exhale slowly"
case 1:
return "Try taking a walk. It can really help clear your head"
case 2:
return "Listen to your favorite music"
case 3:
return "Make a list of what is bringing on your stress"
default:
return "If you can get some exercise in today, that should help!"
}
} else if lowerQuestion.contains("depressed") {
let depressedNumber = question.count % 3
switch depressedNumber {
case 0:
return "Maybe you could hang out with your friends to help"
case 1:
return "Taking a trip might help you"
case 2:
return "Some uplifting music may lift your spirits!"
case 3:
return "Try a board game if you have someone to play it with you."
default:
return "I am sorry to hear that! Take your mind to your happy place!"
}
} else {
let defaultNumber = question.count % 3
if defaultNumber == 0 {
return "That really depends"
} else if defaultNumber == 1 {
return "I think so, yes"
} else if defaultNumber == 2 {
return "I hope tomorrow is better for you!"
} else if defaultNumber == 3 {
return "Ask me again tomorrow"
} else {
return "Try to stay busy to keep your mind off things!"
}
}
}
}