on mouseUp
-- First, get rid of anything that's in the
-- "results" field
put empty into card field "results"
-- Now go through each word of the "input" field
repeat with i = 1 to number of words of card field "input"
-- translate the ith word of the "input" field
put word i of card field "input" into wordToTranslate
-- Since translateWord is a function, it will return a value.
-- So we can take the value that it returns and put it after
-- whatever is already in card field "results"
put translateWord(wordToTranslate) & " " after card field "results"
end repeat
end mouseUp
-- This is a function handler which returns the
-- Morse code translation of the word which is
-- specified by the parameter whichWord
function translateWord whichWord
-- Go through each character of the word to be translated
repeat with j = 1 to number of chars of whichWord
put char j of whichWord into charToTranslate
-- to translate the character, go through each line of the
-- codes field
repeat with i = 1 to number of words of card field "codes"
-- if character 1 of the current line of the codes field
-- matches the character to translate, then the morse code
-- corresponding to the character to translate is the second
-- word of the current line of the codes field
if word 1 of line i of card field "codes" = charToTranslate then
put word 2 of line i of card field "codes" after translation
end if
end repeat
end repeat
-- Since this is a function, it needs a return statement.
-- In this case, we return the translated word (which is stored
-- in the variable "translation")
return translation
end translateWord