方法 - 把數組元素鏈接成一個字符串
.join() - .join(value) sample .join("*") 數組
var landmarks = [];
landmarks.push("My House");
landmarks.push("Front path");
landmarks.push("Flikering streetlamp");
landmarks.push("Leaky fire hydrant");
landmarks.push("Fire station");
landmarks.push("Cat Rescue Center");
landmarks.push("My Old School");
landmarks.push("My friend's house");dom
產生隨機數的方法 Math.random();獲得0-1之間的一個隨機小數
要產生0-10之間的隨機小數,只要Math.random()*10
要取得一個長度爲15的數組的隨機索引,只要Math.floor(Math.random()*15)
Match.floor()只是截取整數部分,不是四捨五入ide
var randomWords = ["Explosion","Cave","Princess","Pen"];
randomWords[Math.floor(Math.random()*4)];idea
決策者程序之一索引
var phrases = [
"That sounds good.",
"Yes, you should definitely do that.",
"I'm not sure that's a great idea.",
"Maybe not today?",
"Computer says no."
];
phrases[Math.floor(Math.random()*5)];字符串