Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 28 additions & 40 deletions 3-conditionals/magic-8-ball/Magic8Ball.swift
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
// Magic 8-Ball 🎱
// Galina Podstrechnaya

let playerName = "Galina"

let playerQuestion = "Will there be any more snowfall in New York for winter 2020? ❄️"

let randomNumber = Int.random(in: 1...9)
// print(randomNumber)

let eightBall: String

switch randomNumber {
case 1:
eightBall = "Yes - definitely"
case 2:
eightBall = "It is decidedly so"
case 3:
eightBall = "Without a doubt"
case 4:
eightBall = "Reply hazy, try again"
case 5:
eightBall = "Ask again later"
case 6:
eightBall = "Better not tell you now"
case 7:
eightBall = "My sources say no"
case 8:
eightBall = "Outlook not so good"
case 9:
eightBall = "Very doubtful"
default:
eightBall = "Error"
}

print("\(playerName)'s Question: \(playerQuestion)")

// Challenge:
// playerName.isEmpty ? print("Question: \(playerQuestion)") : print("\(playerName) asks: \(playerQuestion)")

// MARK: - Magic 8-Ball
// Credit: Patrick Jakobsen

let playerName = "Pallepadehat"
let playerQuestion = "Will it rain tomorrow?"

// All possible Magic 8-Ball answers
let answers = [
"Yes - definitely",
"It is decidedly so",
"Without a doubt",
"Reply hazy, try again",
"Ask again later",
"Better not tell you now",
"My sources say no",
"Outlook not so good",
"Very doubtful"
]

// Pick a random answer
let eightBall = answers.randomElement() ?? "Error"

// Print the question
playerName.isEmpty
? print("Question: \(playerQuestion)")
: print("\(playerName) asks: \(playerQuestion)")

// Print the answer
print("Magic 8 Ball's answer: \(eightBall)")