How Do I Use The 'Or' Function

I am creating a nifty program that tells you if the number you enter is divisible by the numbers 1-9. I’m currently on the section that tells if it’s divisible by 5. The trick is if the last digit in the number ends in a 5 or 0, the number is divisible by 5. I tried using this to see if I could make it work:

-- Determines if initial number is divisible by 5
if (last character of numString) = 0 or 5 then
	set fiveCheck to "true"
else
	set fiveCheck to "false"
end if

However, when I run this, I get an error from the editor saying: ‘error “Can’t make 5 into type boolean.” number -1700 from 5 to boolean’. I’m fairly new to AppleScript and it’d be great if I could get some help on this.

*Some important things to note are that the variable ‘numString’ is just the text returned of a dialog where you enter in the number you want.


-- Script: Check the divisibility of a real or integer by 5, without increasing the signs of the remainder.

set aNumber to 625.5 -- real or integer number
set numString to aNumber as text -- coerce to string
set lastChar to last character of numString -- last character

if (lastChar = "0") or (lastChar = "5") then -- compare string with string (not string with number), OR statement has this syntax (the results of left and right operands should be boolean), that is, we compare is TRUE one of 2 conditions or not
	set fiveCheck to true -- boolean result, not string
else
	set fiveCheck to false -- boolean result, not string
end if

Other way:


-- Script: Check the divisibility of a real or integer by 5, without increasing the signs of the remainder.
set aNumber to 625.5

if last character of (aNumber as text) is in {"0", "5"} then
	set fiveCheck to true
else
	set fiveCheck to false
end if

Or:


-- Script: Check the divisibility of a real or integer by 5, without increasing the signs of the remainder.
set aNumber to 625.5

if item -1 of (aNumber as text) is in {"0", "5"} then
	set fiveCheck to true
else
	set fiveCheck to false
end if

And finally, a joke: Adding the TRUE to the OR statement turns its result into an “eternal” TRUE:


if ("Elefant" is "Mickey mouse") or true then return "Yep, elefant is Mickey mouse"
--> RESULT: "Yep, elefant is Mickey mouse"

if ("Elefant" is not "Mickey mouse") or true then return "Yep, elefant is Mickey mouse"
--> RESULT: "Yep, elefant is Mickey mouse"

bez9199. Welcome to the forum.

The question you ask is about the operator “or” and this question has been fully answered by KniazidisR. FWIW, the following is a different approach to the intended purpose of the script, although it only works with whole numbers.

display dialog "Enter a number to divide:." default answer ""
set theDividend to (text returned of result) as integer
if theDividend = 0 then error number -128

set theResult to ""

repeat with theDivisor from 1 to theDividend -- change theDividend to 9 to limit divisor to 9
	if (theDividend mod theDivisor) = 0 then
		set theResult to theResult & theDivisor & ", "
	end if
end repeat

display dialog "The number " & (theDividend as text) & " is divisible by the numbers " & (text 1 thru -3 of theResult) buttons "OK" cancel button 1 default button 1

Thank you a lot for your detailed and helpful answers! I really appreciate it.