jetbrains-academy / kotlin-onboarding-introduction

The introduction to the Kotlin Onboarding course
MIT License
9 stars 2 forks source link

(course question) Hangman final test #237

Open p3p3fr0g opened 1 month ago

p3p3fr0g commented 1 month ago
`fun playGame(secret: String, maxAttemptsCount: Int): Unit {
    var currentUserWord = getHiddenSecret(wordLength)
    var complete = false
    var guess: Char
    var attempts = 0
    while (true) {
        if (isLost(complete, attempts, maxAttemptsCount)) {
            println("Sorry, you lost! My word is $secret")
            break
        }
        if (isWon(complete, attempts, maxAttemptsCount)) {
            println("Congratulations! You guessed it!")
            break
        }
        guess = safeUserInput()
        currentUserWord = getRoundResults(secret, guess, currentUserWord)
        complete = isComplete(secret, currentUserWord)
        attempts++
    }
}`

When I run my program, it exits correctly after 9 failed guesses or solving the puzzle. However, when running the tests (that appear to test it with random inputs?) it gives me this error

Try to run the main function with the user input: V A W G T C U R D J L P Z Q F O K I X B Y H N M E S , the function must process the input and exit, but the current version of the function waits more user inputs, it must be fixed.

Now from what I gather, the program should be terminating after 8 inputs not 9, so if i change the initialization from var attempts = 0 to var attempts = 1, and run the program, it terminates after not getting the word in 8 tries, but now gives me an additional failed test ("You are asking the user to enter data fewer times than required in the task!") and still gives me failure of the not terminating test?

Not understanding why when I run the program in the terminal it successfully terminates but doesn't in the course's test, is this an error in the program or the test?, and also not understanding why if max attempts is supposed to be 8, the other test passes on 9 tries but fails on 8?

p3p3fr0g commented 1 month ago

also why when i selected my code to be code in the editor did it not preserve my line breaks? apparently you have to select code twice?