DayByDay/Quiz/PraisePhrases.swift
32 lines · 738 bytes
2 symbols in this file
1//
2// PraisePhrases.swift
3// DayByDay
4//
5
6nonisolated struct PraisePhrases {
7 static let all = [
8 "Great job!",
9 "You got it!",
10 "Super!",
11 "Way to go!",
12 "Awesome!",
13 "Yes, that's right!",
14 "Nice work!",
15 "You did great!",
16 "Hooray!",
17 "Fantastic!",
18 ]
19
20 private var last: String?
21
22 /// A random phrase, never the same as the previous one.
23 mutating func next(using rng: inout some RandomNumberGenerator) -> String {
24 let phrase = Self.all.filter { $0 != last }.randomElement(using: &rng)!
25 last = phrase
26 return phrase
27 }
28
29 static func correction(for name: String) -> String {
30 "That's \(name)! Try again."
31 }
32}