Created
December 5, 2022 19:36
"Bank Heist" exercise from Codeacademy's "Learn Go: Conditionals" chapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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