Animal Sanctuary

I am getting this error:

Sanctuary.kt:3:7: warning: variable 'responsibilites' is never used
  val responsibilites = listOf("feed the chimps", "play a random game", "conduct a health check on Foxie")
      ^
Sanctuary.kt:5:7: warning: variable 'responsibilitiesComplete' is never used
  var responsibilitiesComplete = 0
      ^
Sanctuary.kt:6:7: warning: variable 'timeSpent' is never used
  var timeSpent = 0
      ^
Sanctuary.kt:7:7: warning: variable 'totalShiftTime' is never used
  val totalShiftTime = 4
      ^

This is my code:

fun main() {
  // Write your code below 🏞
  val responsibilites = listOf("feed the chimps", "play a random game", "conduct a health check on Foxie")

  var responsibilitiesComplete = 0
  var timeSpent = 0
  val totalShiftTime = 4
}

It just means you have to use it in your code and then it won’t throw an error. A println for each would make it not throw an error for example.

I have now run into this error:

Sanctuary.kt:54:23: error: expecting ')
  } else if (timeSpent => totalShiftTime && responsibilitiesComplete == responsibilities.size) {
                      ^
Sanctuary.kt:54:24: error: expecting an expression
  } else if (timeSpent => totalShiftTime && responsibilitiesComplete == responsibilities.size) {
                       ^
Sanctuary.kt:54:24: error: unexpected tokens (use ';' to separate expressions on the same line)
  } else if (timeSpent => totalShiftTime && responsibilitiesComplete == responsibilities.size) {
                       ^
Sanctuary.kt:56:5: error: unexpected tokens (use ';' to separate expressions on the same line)
  } else {
    ^
Sanctuary.kt:54:14: error: type mismatch: inferred type is Int but Boolean was expected
  } else if (timeSpent => totalShiftTime && responsibilitiesComplete == responsibilities.size) {
             ^

This is my current code:

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

  val responsibilities = mutableListOf("feed the chimps", "play a random game", "conduct a health check on Foxie")
  var responsibilitiesComplete = 0
  var timeSpent = 0
  val totalShiftTime = 4
  val 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 Jubliee....")
  chimpsHaveEaten["Jubliee"] = true

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

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

  timeSpent += 1
  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 += 1
  responsibilitiesComplete++

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

  println("\nNext, ${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 += 1
  responsibilitiesComplete++
  println("You've now completed $responsibilitiesComplete / ${responsibilities.size} responsibilities.")

  if (timeSpent <= totalShiftTime && responsibilitiesComplete == responsibilities.size) {
    println("\nAwesome work! You've completed all of your responsibilities for a day, and you can clock out.")
  } else if (timeSpent => totalShiftTime && responsibilitiesComplete == responsibilities.size) {
    println("\nGreat job today! You've completed all of your responsibilities but with over time.")
  } else {
    println("\nYou went over time and did not complete all of your responsibilities.")
  }
}

Your conditional has an error, I’ll give you an example to give you a clue

println(1==1)
// true
println(1>1)
// false
println(1>=1)
// true 
println(1=>1)
// Expecting ')' Unexpected tokens (use ';' to separate expressions on the same line)

2 Likes

Alright, I get you. Thanks.

1 Like