2017-07-28 9 views
0

のでautomaicallyファイルの別々のNode.jsに記載された配列からランダムなエントリを取得しようとイムは、外部の配列ノードからランダムなエントリを選択

機能コード

var replies = require('./replies'); 
function followed(event) { 
    var name = event.source.name; 
    var flname = event.source.screen_name; 
    var myArray = [replies]; 
    var item = myArray[(Math.random()*myArray.length)|0]; 
    var followtweet = '@' + flname + item; 
    if(flname != "UserName") { 
    tweetIt(followtweet); 
    console.log('\[email protected]' + flname + ' Followed You'); 
    console.log('\nYou Tweeted:\n ' + followtweet); 
} else { 
    console.log(' Interferance From Another Bot! \n'); 
} 

} 

外付アレイ

module.exports = { 
    followedone:   'one', 
    followedtwo:   'two', 
    followedthre:   'three', 
    replyone:   ' one', 
    replytwo:   ' two', 
    replythre:   ' three',  

}

これを実行して関数を実行すると、これが発生します

@LandscapesLucid Followed You 

You Tweeted: 
@LandscapesLucid[object Object] 

Waiting For The Next Action 

配列

答えて

0

にあなたがこの

var item = myArray[(Math.random()*myArray.length)|0]; 

から変更しようとすることができるようにそのだけの代わりに1〜2または3のいずれかの[オブジェクトのオブジェクト]を示す理由は、私はわからないんだけどこれに?

var item = myArray[Math.floor(Math.random()*items.length)]; 
関連する問題