fun safeUserInput(wordLength: Int, alphabet: String): String {
println("Please input your guess. It should be of length $wordLength, and each symbol should be from the alphabet: $alphabet.")
val guess: String = safeReadLine()
isCorrectInput(guess, wordLength, alphabet)
return guess
}
fun isCorrectInput(userInput: String, wordLength: Int, alphabet: String): Boolean {
var isCorr = true
if (userInput.length != wordLength) {
println("The length of your guess should be $wordLength characters! Try again!")
isCorr = false
}
var flag: Boolean = true
for (i in userInput) {
if (i !in alphabet) {
flag = false
}
}
if (!flag) {
println("All symbols in your guess should be the $alphabet alphabet characters! Try again!")
isCorr = false
}
return isCorr
}
But the initial idea was to ask user about the correct input while the correct input is not passed
The current implementation works with
But the initial idea was to ask user about the correct input while the correct input is not passed