# CFLib.org – Common Function Library Project

## Magic8Ball(question)

##### Last updated July 14, 2009

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Pass this UDF a Yes/No question, and it will return a prediction. Based on the Magic 8-Ball by Tyco Toys.

Return Values:
Returns a string.

Example:

<CFOUTPUT>
Is today going to be a good day? #Magic8Ball("Is today going to be a good day?")#<BR>
What is 3+3? #Magic8Ball("What is 3+3?")#<BR>
</CFOUTPUT>

Parameters:

Name Description Required
question Yes/No question you want to ask the magic 8 ball. Yes

Full UDF Source:

/**
* Pass this UDF a Yes/No question, and it will return a prediction.
*
* @param question      Yes/No question you want to ask the magic 8 ball. (Required)
* @return Returns a string.
* @author Rob Brooks-Bilson (rbils@amkor.com)
* @version 1, July 14, 2009
*/
function Magic8Ball(question){
var validQuestion=False;
var wordList="am,are,can,could,couldn't,will,would,wouldn't,won't,was,wasn't,must,musn't,may,if,is,isn't,should,shouldn't,do,did,don't,shall,shant";
var i=0;
for (i=1; i lte ListLen(wordList); i=i+1) {
if (ListFirst(question, " ") EQ ListGetAt(wordList, i)){
validQuestion=True;
break;
}
}
// Initialize an array with all of the responses
Answer[4] = "My sources say NO";
Answer[5] = "As I see it, yes";
Answer[8] = "Signs point to yes";
Answer[12] = "It is decidedly so";
Answer[13] = "Don't count on it";
Answer[14] = "My sources say Yes";
Answer[18] = "Outlook not so good";
Answer[19] = "You may rely on it";
Answer[20] = "Better not tell you now";

if (ValidQuestion EQ True)
else
return "I'm not sure I understand.  Please rephrase the question and ask again.";
}

### Search CFLib.org

QueryDeleteRows
November 04, 2017

May 11, 2016