Skip to content

Instantly share code, notes, and snippets.

@erainey
Created December 5, 2022 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erainey/0087f8852316bfdb13d16dd831f8515e to your computer and use it in GitHub Desktop.
Save erainey/0087f8852316bfdb13d16dd831f8515e to your computer and use it in GitHub Desktop.
"Bank Heist" exercise from Codeacademy's "Learn Go: Conditionals" chapter
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
isHeistOn := true
eludedGuards := rand.Intn(100)
fmt.Println("FIRST STEP: THE GUARDS")
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 {
fmt.Println("SECOND STEP: THE VAULT")
}
if (isHeistOn && openedVault >= 70) {
fmt.Println("Grab and GO!")
} else if (isHeistOn && openedVault < 70) {
isHeistOn = false
fmt.Println("The vault can't be opened!")
}
leftSafely := rand.Intn(5)
if isHeistOn {
fmt.Println("THIRD STEP: THE ESCAPE")
switch leftSafely {
case 0:
isHeistOn = false
fmt.Println("You failed the heist!")
case 1:
isHeistOn = false
fmt.Println("You slipped on a banana peel on the way out!")
case 2:
isHeistOn = false
fmt.Println("Your distinctive ringtone went off from a spam call and alerted a patrolling guard!")
case 3:
isHeistOn = false
fmt.Println("A viewer on your TikTok livestream ratted you out to the cops!")
default:
fmt.Println("Start the getaway car!")
}
}
if isHeistOn {
amtStolen := 10000 + rand.Intn(1000000)
fmt.Println("You got away with", amtStolen)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment