3.1 12 digit product codes: Check if total is a multiple of 10 (one line of input)

Scratch solution

View solution

This is just one of many possible solutions:

when green flag clicked
set [index v] to [1]
set [product code v] to []
set [total 1 v] to [0]
set [total 2 v] to [0]
set [total v] to [0]
ask [Enter a 12 digit product code:] and wait
change [product code v] by (answer)
if <(length of (product code)) = [12]> then
  repeat (6)
    set [total 1 v] to ((total 1) + (letter (index) of (product code)))
    change [index v] by (1)
    set [total 2 v] to ((total 2) + (letter (index) of (product code)))
    change [index v] by (1)
  set [total v] to (((total 1) * (3)) + (total 2))
  if <((total) mod (10)) = [0]> then
    say [Valid product code!]
    say [Invalid product code!]
  say [Please enter a 12 digit number!]

Back to programming challenge