2012-04-17 67 views
-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')它從數組獲取一個值我將如何轉換這八個球腳本紅寶石

+3

谷歌「僱用一個自由職業者」,或者,*你嘗試過什麼?* – alex 2012-04-17 12:16:31

回答

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 
+1

更好地使用常數。這樣你可以反覆創建相同的數組。仍然有效:) – ayckoster 2012-04-17 12:17:56

+0

@ayckoster這是真的,男人:) – fl00r 2012-04-17 12:18:20