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
6 changes: 4 additions & 2 deletions SwiftUI/project2/GuessTheFlag/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct ContentView: View {

@State private var showingScore = false
@State private var scoreTitle = ""
@State private var score = 0

var body: some View {
ZStack {
Expand Down Expand Up @@ -57,7 +58,7 @@ struct ContentView: View {
Spacer()
Spacer()

Text("Score: ???")
Text("Score: \(score)")
.foregroundStyle(.white)
.font(.title.bold())

Expand All @@ -68,13 +69,14 @@ struct ContentView: View {
.alert(scoreTitle, isPresented: $showingScore) {
Button("Continue", action: askQuestion)
} message: {
Text("Your score is ???")
Text("Your score is \(score)")
}
}

func flagTapped(_ number: Int) {
if number == correctAnswer {
scoreTitle = "Correct"
score += 1
} else {
scoreTitle = "Wrong"
}
Expand Down