Bank Heist - Go project

excercize for Go: https://www.codecademy.com/courses/learn-go/projects/bank-heist

what’s wrong with this code? it seem correct to me:

if eludedGuards >= 50 {
fmt.Println(“Looks like you’ve managed to make it past the guards. Good job, but remember, this is the first step.”)
}
else {
isHeistOn = false
fmt.Println(“Plan a better disguise next time?”)
}

but the system continue to say:

command-line-arguments

./main.go:16:3: syntax error: unexpected else, expecting }

and so I cannot check if i’m doing a good job

1 Like
}
else {

Gives the syntax error. Should be:

} else {

1 Like

I tried, but nothig’s changed…
if eludedGuards >= 50 {
fmt.Println(“Looks like you’ve managed to make it past the guards. Good job, but remember, this is the first step.”)
} else {
isHeistOn = false
fmt.Println(“Plan a better disguise next time?”)
}

What error are you getting? I merely looked at solving your

./main.go:16:3: syntax error: unexpected else, expecting }

exactly, it’s that error. The problem is that it seems there’re not error in my code. It’s possible a bug

Could you please present all your code using the </> button in the post editor? And please tell me the exact error you are getting.

package main

import (
  "math/rand"
  "time"
  "fmt"
)

func main() {
  rand.Seed(time.Now().UnixNano())
  isHeistOn := true
  eludedGuards := rand.Intn(100)
  if eludedGuards >= 50 {
    fmt.Println("Looks like you've managed to make it past the guards. Good job, but remember, this is the first step.")
  } else {
    isHeistOn = false
    fmt.Println("Plan a better disguise next time?")
    }

  
  openedVault := rand.Intn(100)
  if isHeistOn && openedVault >=70 {
   fmt.Println("Grab and GO!") 
  }
  else if isHeistOn {
    isHeistOn = false
    fmt.Println("vault can't be opened")
  }
  fmt.Println("eludedGuards has a value of", eludedGuards) 
  fmt.Println("isheistOn has a value of", isHeistOn)
}

After I hinted you on fixing the error message you didn’t think of fixing this too?

}
  else if isHeistOn {

ok, it worked! I think it was like you said! So in Go I have always to put else on the same line of } ?
Thank you anyway

1 Like

It is exactly what the error message said, expecting a } and not an else.

1 Like