-3
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var answers = new Array(
"Yes.",
"No.", 
"My sources are pointing toward yes.", 
"It's possible.",
"Very unlikely.", 
"Can you repeat the question?",
"Absolutely not.", 
"Sure.",
"Ask again later."
);
function fortune() {
num = Math.round( (answers.length - 1) * Math.random());
return answers[num];
}
//  End -->
</script>

然后当我调用fortune('text')它时,它会从数组中获取一个值

4

1 回答 1

2
def fortune
  ["Yes.",
   "No.", 
   "My sources are pointing toward yes.", 
   "It's possible.",
   "Very unlikely.", 
   "Can you repeat the question?",
   "Absolutely not.", 
   "Sure.",
   "Ask again later."].sample
end
于 2012-04-17T12:16:48.380 回答