exercice terminé
This commit is contained in:
1 parent
d79c543c72
commit
8bc08ec525
2 files changed
+43
-2
No files matched your search
+27
-2
@@ -23,14 +23,39 @@
|
||||
cards = [
|
||||
{ value: "7", suit: "clubs" },
|
||||
{ value: "king", suit: "hearts" },
|
||||
{ value: "ace", suit: "spades" }
|
||||
{ value: "ace", suit: "spades" },
|
||||
# { value: "blork", suit: "club"}
|
||||
]
|
||||
|
||||
def hand_score(cards)
|
||||
# À compléter.
|
||||
score = 0
|
||||
|
||||
cards.each do |card|
|
||||
value = Integer(card[:value], exception: false)
|
||||
if value
|
||||
score += value
|
||||
else
|
||||
case card[:value]
|
||||
when "jack"
|
||||
score += 11
|
||||
when "queen"
|
||||
score += 12
|
||||
when "king"
|
||||
score += 13
|
||||
when "ace"
|
||||
score += 14
|
||||
else
|
||||
# raise lève une exception et interrompt l'exécution normale du programme.
|
||||
raise ArgumentError, "Valeur de carte inconnue : #{card[:value]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
score
|
||||
end
|
||||
|
||||
# Résultat attendu :
|
||||
#
|
||||
# hand_score(cards)
|
||||
# => 34
|
||||
|
||||
puts hand_score(cards)
|
||||
Reference in new issue
Block a user