Skip to content

Commit

Permalink
Merge pull request mouredev#6042 from didacdev/main
Browse files Browse the repository at this point in the history
Reto mouredev#47 - Swift
  • Loading branch information
kontroldev authored Dec 11, 2023
2 parents 3e1d4bc + 74aef97 commit 491092b
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Foundation

let alphabet = Array("abcdefghijklmnñopqrstuvwxyz")
var letterValues: [Character: Int] = [:]

for (index, letter) in alphabet.enumerated() {
letterValues[letter] = index + 1
}

func getPoints(word: String) -> Int {
var points = 0

for letter in word {
if let number = letterValues[letter] {
points += number
}
}

return points
}

func play() {
var finish = false

while !finish {
print()
print("Escribe una palabra:")

if let word = readLine(){

let points = getPoints(word: word)
print()
print("Puntuación: \(points)")

if points == 100 {
print("Has ganado!")
finish = true
}
}
}
}

play()


0 comments on commit 491092b

Please sign in to comment.