Skip to content

Commit

Permalink
reto mouredev#47 didacdev
Browse files Browse the repository at this point in the history
  • Loading branch information
D1d4cum committed Dec 10, 2023
1 parent bfcb717 commit 74aef97
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 74aef97

Please sign in to comment.