2017-05-06 8 views
-4

配列から引っ張るランダムな単語の文字数に対して空白の文字スペースの数を表示したいと考えています。JavaScriptで - 文字列に変数を掛けて表示する

これは、クラスプロジェクトのハングマンゲーム用です。私は無作為に引っ張られた単語とその単語の文字数を持っていますが、その番号を割り当てた変数を使用しようとすると少し難解です。

+2

を? – mayersdesign

+2

あなたが試したコードを投稿できますか? – Sreekanth

+2

ようこそ[so]!このサイトでは、自分でコードを書くことができます**。 ** [もっと研究をして](// meta.stackoverflow.com/questions/261592)**あなたが問題を抱えていると、あなたが試みたものを投稿することができます** (** stackoverflow.com/help/mcve)を提供しています。私は良い質問と[完璧な質問]を読むことをお勧めします(http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。また、[ツアー]を取って** [this](// meta.stackoverflow.com/questions/347937/)**を必ず読んでください。 –

答えて

0

次のコード試すことができます:あなたがこれまでにどのようなコードを持っているん

// The array of words you have 
var $words = [ 
    'Totidem', 
    'Pugnabant', 
    'Calidis', 
    'Circumfluus', 
    'Formaeque' 
]; 
// Pick a random array index 
var $idx = Math.floor(Math.random() * $words.length); 
// Get the word in the index equal to $idx 
var $word = $words[$idx]; 
// Generate the repeated string. In case you like to display a different 
// character, replace the `.join(" ")` with the character you need. For 
// example `.join("_")` or `.join("_=_")` 
var $repeated_string = Array(1 + $word.length).join(" ") 
関連する問題