Sanctuary.kt - error: unexpected tokens (use ';' to separate expressions on the same line)

I’m really close to completing https://www.codecademy.com/courses/learn-kotlin/projects/kotlin-animal-sanctuary

But I’m getting the following error messages, I’ve googled it, read every reference I can find on github and stackoverflow, but still getting the same results, thanks in advance for any feedback.

Sanctuary.kt:51:70: error: unexpected tokens (use ‘;’ to separate expressions on the same line)
println(“Great job completing your responsibilities on time.”) else if (timeSpent >= totalShiftTime && responsibilitiesComplete == responsibilities.size) {

Sanctuary.kt:52:59: error: unexpected tokens (use ‘;’ to separate expressions on the same line)
println(“Responsibilities complete with overtime.”) else {

Here is my code:

fun main() {
  // Write your code below 🏞

  var responsibilities = listOf("feed the chimps", "play a random game", "conduct a health check on Foxie")

  var responsibilitiesComplete = 0
  var timeSpent = 0
  val totalShiftTime = 4
  var foxiesHealthCheck = mutableMapOf<String, Any?>()

  var chimpsHaveEaten = mutableMapOf("Bonnie" to false, "Jubilee" to false, "Frodo" to false, "Foxie" to false)

  println("First, ${responsibilities[0]}")

  println("Feeding Bonnie...")
  chimpsHaveEaten["Bonnie"] = true
  println("Feeding Jubilee...")
  chimpsHaveEaten["Jubilee"] = true
  println("Feeding Frodo...")
  chimpsHaveEaten["Frodo"] = true
  println("Feeding Foxie...")
  chimpsHaveEaten["Foxie"] = true

  timeSpent++
  responsibilitiesComplete++

  println("All chimps have now been fed! You've completed $responsibilitiesComplete / ${responsibilities.size} responsibilities.")

  println("\nNext, ${responsibilities[1]}.")

  val games = mutableSetOf("tug-of-war with a blanket", "catch and throw", "number game")
  val randomGame = games.random()

  println(randomGame)
  timeSpent++
  responsibilitiesComplete++

  println("Each chimp has now played a game of $randomGame! You've completed $responsibilitiesComplete / ${responsibilities.size} responsibilities.")

  println("Next, ${responsibilities[2]}")

  foxiesHealthCheck.put("temperature", 37.2)
  foxiesHealthCheck.put("mood", "happy")
  println("Foxie has a temperature of ${foxiesHealthCheck["temperature"]} and is feeling ${foxiesHealthCheck["mood"]}.")
  timeSpent++
  responsibilitiesComplete++

  println("Youve now completed $responsibilitiesComplete / ${responsibilities.size} responsibilities.")

  if (timeSpent <= totalShiftTime && responsibilitiesComplete == responsibilities.size) {
      println("Great job completing your responsibilities on time.") else if (timeSpent >= totalShiftTime && responsibilitiesComplete == responsibilities.size) {
      println("Responsibilities complete with overtime.") else {
      println("Responsibilities not complete and took extra time.")
      }
    }
  }
  

}

Looks like you’re missing a couple of closing curly braces ( } ), so the compiler thinks you’re trying to use more than one expression on the same line.

1 Like

Thanks for helping me clean that up el_cocodrilo, I’m probably fixating on the concept a bit much and not syntax enough, it now runs!

:raised_hands:
:space_invader:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.