Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Need help converting simple Applescript to Javascript

skepticsensei

New Coder
Hey everyone!

So, I wrote this silly little script that does a magic card trick way back in 2008. (user thinks of a card, and the script tells you what it is.)
Thought about it again today and decided to check it out.

Problem is, back then I wrote it in Applescript.
I would like to convert it to Javascript so I can use it now.
Its not complex, just a series of if/then style statements, and a simple math formula.

But I know nothing of Java, thought I'd start here and seek advice.

Any help would be appreciated.

Thanks!

AppleScript:
display dialog "Think of any playing card in a normal deck...
And for the moment, just forget about the suit, and the color of your card. Only think of the number or letter."

property questionList : {"Is the rank of your card equal to any of these? 3, Jack, 5, Ace, 9, 7?", "Ok, how about these? 10, 3, 6, 2, 7, Jack?", "Almost done, how about these? 5, Queen, 6, 7, 4?", "Last round: Queen, 9, 8, Jack, 10"}

set theResult to 0
repeat with i from 1 to 4
   set b to button returned of (display dialog item i of questionList buttons {"No", "Yes"})
   if b is "Yes" then set theResult to (theResult + (2 ^ (i - 1))) as integer
end repeat

--figure out the color
set theColor to 0
display dialog "Great, now I want you to remember the color of your card. imagine it bright and vivid in your mind."
if button returned of result is "OK" then
   display dialog "Ok, I am getting something, does the word 'cherry' mean anything to you?" buttons ["Nope", "Yes, it does"]
   if button returned of result is "Yes, it does" then
       set theColor to "red"
   else
       set theColor to "black"
       display dialog "Oh.. well I meant 'Black Cherry', we'll move on."
   end if
   if theResult is 1 then set theResult to "Ace"
   if theResult is 2 then set theResult to "Two"
   if theResult is 3 then set theResult to "Three"
   if theResult is 4 then set theResult to "Four"
   if theResult is 5 then set theResult to "Five"
   if theResult is 6 then set theResult to "Six"
   if theResult is 7 then set theResult to "Seven"
   if theResult is 8 then set theResult to "Eight"
   if theResult is 9 then set theResult to "Nine"
   if theResult is 10 then set theResult to "Ten"
   if theResult is 11 then set theResult to "Jack"
   if theResult is 12 then set theResult to "Queen"
   if theResult is 0 then set theResult to "King"
   if theResult is 15 then set theResult to "--You cheated, it wasn't in all four!"
end if

if theColor is "red" then
   display dialog "Your card is a Heart correct?" buttons ["No, its not", "Yes, it is"]
   if button returned of result is "Yes, it is" then
       display dialog "I thought so, you're thinking of the " & theResult & " of Hearts" buttons {"Have a great day!"} default button 1
   else
       display dialog "Oh, well I sometimes have trouble with the " & theResult & " of Diamonds" buttons {"Have a great day!"} default button 1
   end if
else if theColor is "black" then
   display dialog "Your card is a Spade correct?" buttons ["No, its not", "Yes, it is"]
   if button returned of result is "Yes, it is" then
       display dialog "I thought so, you're thinking of the " & theResult & " of Spades" buttons {"Have a great day!"} default button 1
   else
       display dialog "Oh, well I sometimes have trouble with the " & theResult & " of Clubs" buttons {"Have a great day!"} default button 1
   end if
end if
 

New Threads

Buy us a coffee!

Back
Top Bottom