From d3017efad4ad50a5f8f9db0adeeca25e3f273795 Mon Sep 17 00:00:00 2001 From: Patrick Jakobsen <97399891+Pallepadehat@users.noreply.github.com> Date: Sun, 17 May 2026 17:15:09 +0300 Subject: [PATCH] New solution --- 3-conditionals/magic-8-ball/Magic8Ball.swift | 68 ++++++++------------ 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/3-conditionals/magic-8-ball/Magic8Ball.swift b/3-conditionals/magic-8-ball/Magic8Ball.swift index e07c59f..c5f1aeb 100644 --- a/3-conditionals/magic-8-ball/Magic8Ball.swift +++ b/3-conditionals/magic-8-ball/Magic8Ball.swift @@ -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)")