Challenges, my solutions


#1

Challenge 1: I had to add “else” here or there was an error message.

private fun auraColor(isBlessed: Boolean, healthPoints: Int, isImmortal: Boolean) =
when (isBlessed && healthPoints > 50 || isImmortal) {
true -> “GREEN”
else -> “NONE”
}

Challenges 2 and 3: I altered the castFireballs function. Again I had to add “else” or an error message appeared.

private fun castFireball(numFireballs: Int = 2, inebStatus: Int = 10) =
if (numFireballs > 0) {
println(“A glass of Fireball springs into existence (x$numFireballs).”)
when (inebStatus) {
in 1…10 -> “tipsy”
in 11…20 -> “sloshed”
in 21…30 -> “soused”
in 31…40 -> “stewed”
in 41…50 -> “…t0aSt3d”
else -> “The fireball has no effect.”
}
} else {
println(“No fireballs today!”)
}

Then I changed the printPlayerStatus function adding one line.

private fun printPlayerStatus(

println(“Inebriation Status: ${castFireball(2, 5)}”)
}