Hi! I did the bonus slots challenge and realized I completed differently than the solution.
Is the way I completed okay? or considered dirty code that should be cleaned up?
struct ContentView: View {
var options = ["apple", "cherry", "star"]
@State var image1 = "apple"
@State var image2 = "cherry"
@State var image3 = "star"
@State var credits = 1000
var body: some View {
VStack {
Spacer()
.frame(width: 100.0/*@END_MENU_TOKEN@*/, height: /*@START_MENU_TOKEN@*/21.0)
Text("Swift UI Slots")
.font(.largeTitle)
.fontWeight(.semibold)
Spacer()
Text("Credits: " + String(credits))
.font(.title2)
Spacer()
HStack{
Spacer()
Image(image1)
.resizable(resizingMode: .stretch)
.aspectRatio(contentMode: .fit)
Image(image2)
.resizable(resizingMode: .stretch)
.aspectRatio(contentMode: .fit)
Image(image3)
.resizable(resizingMode: .stretch)
.aspectRatio(contentMode: .fit)
Spacer()
}
Spacer()
Button("Spin") {
image1 = options.randomElement()!
image2 = options.randomElement()!
image3 = options.randomElement()!
if image1 == "apple" {
if image1 == image2 &&
image2 == image3 {
credits += 200
}
}
else if image1 == "cherry" {
if image1 == image2 &&
image2 == image3 {
credits += 100
}
}
else if image1 == "star" {
if image1 == image2 &&
image2 == image3 {
credits += 50
}
}
// point deductions
if image1 != image2 ||
image2 != image3 ||
image1 != image3 {
credits -= 50
}
}
.font(.title)
.foregroundColor(.white)
.padding(.horizontal, 48.0)
.padding(.vertical, 15.0)
.background(Color.red)
.cornerRadius(24.0)
Spacer()
.frame(height: 30.0)
}
Also not sure if I posted my code correctly sorry!