--- Begin Message ---
Op 30-4-2020 om 16:16 schreef Roelof Wobben:
nextIsOdd := true.
     aString reverseDo: [:digit |
         digit = Character space ifFalse: [
         nextIsOdd
             ifTrue:  [oddSum := ...]
             ifFalse: [evenSum := ...].
         nextIsOdd := nextIsOdd not]].

hmm,

Still no luck with this code :

cardNumber := '4539 1488 0343 6467'.
oddSum := 0.
evenSum := 0.
nextIsOdd := true.
     cardNumber reverseDo: [:digit |
         digit = Character space ifFalse: [
         nextIsOdd
             ifTrue:  [oddSum := oddSum + digit asInteger ]
             ifFalse: [evenSum := ((digit asInteger * 2) > 9)
    ifTrue: [evenSum + ((digit asInteger * 2) - 9) ]
    ifFalse: [ evenSum + (digit asInteger * 2) ]].
            nextIsOdd := nextIsOdd not]].
^ oddSum + evenSum

the answer schould be 57 where I get 1157

So some debugging to do



--- End Message ---

Reply via email to