Practical Exam-- Solutions
Practical Exam-- Solutions
Script for the "Count it" button:
on mouseUp
put 0 into total
repeat with i = 1 to number of words of card field "text"
if word 1 of card field "input" = word i of card field "text" then
add 1 to total
end if
end repeat
put "The word" && word 1 of card field "input" && "appears" && total && "times in the text" into card field "results"
end mouseUp
Script for the "Reverse it" button:
on mouseUp
put empty into card field "results"
repeat with i = 1 to number of chars of word 1 of card field "input"
put char i of word 1 of card field "input" before card field "results"
end repeat
end mouseUp
Script for the "Palindrome?" button:
on mouseUp
send mouseUp to button "Reverse it"
if word 1 of card field "results" = word 1 of card field "input" then
put "The word" && word 1 of card field "input" && "is a palindrome." into card field "results"
else
put "The word" && word 1 of card field "input" && "is not a palindrome." into card field "results"
end if
end mouseUp