So I am working on the war card app and am running into a weird thing the var playerCard or cpuCardin the func deal() is saying it cannot be found in the scope. Every other location where the they are named it works not sure what I am missing.
Using Xcode ver 15.4 thanks for the help.
Here is the code
import SwiftUI
struct ContentView: View {
@State var playerCard = "card3"
@State var cpuCard = "card4"
var playerScore = 0
var cpuScore = 0
var body: some View {
ZStack{
Image("background-plain")
.resizable()
.ignoresSafeArea()
VStack{
Spacer()
Image("logo")
Spacer()
HStack{
Spacer()
Image(playerCard)
Spacer()
Image(cpuCard)
Spacer()
}
Spacer()
Button(action: {
deal()
}, label: {
Image("button")
})
Spacer()
HStack{
Spacer()
VStack{
Text("Player")
.font(.headline)
.padding(.bottom, 10.0)
Text(String(playerScore))
.font(.largeTitle)
}
Spacer()
VStack{
Text("CPU")
.font(.headline)
.padding(.bottom, 10.0)
Text(String(cpuScore))
.font(.largeTitle)
}
Spacer()
}
Spacer()
} .foregroundColor(.white)
Spacer()
}
}
}
func deal(){
playerCard = "card" + String(Int.random(in: 2...14))
cpuCard = "card" + String(Int.random(in: 2...14))
}
#Preview {
ContentView()
}