-4
我想显示一些空白字母空格数=从数组中抽取的随机单词的字母数。在JavaScript中 - 显示一个字符串乘以一个变量
这是一个类项目的hang子手游戏。我有随机拉的单词和该单词中的字母数量,但试图使用我分配了该数字的变量也证明有点棘手。
任何帮助表示赞赏!
我想显示一些空白字母空格数=从数组中抽取的随机单词的字母数。在JavaScript中 - 显示一个字符串乘以一个变量
这是一个类项目的hang子手游戏。我有随机拉的单词和该单词中的字母数量,但试图使用我分配了该数字的变量也证明有点棘手。
任何帮助表示赞赏!
你可以试试下面的代码:
// 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(" ")
你有什么代码,使远吗? – mayersdesign
您可以发布您尝试过的任何代码吗? – Sreekanth
欢迎来到[so]!在这个网站,你应该尝试**自己编写代码**。后** [做更多的研究](//meta.stackoverflow.com/questions/261592)**如果你有问题,你可以**发布你已经尝试**与清晰的解释是什么是'工作**并提供[** Minimal,Complete和Verifiable示例**](// stackoverflow.com/help/mcve)。我建议阅读[问]一个好问题和[完美问题](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要参加[游览]并阅读[this](// meta.stackoverflow.com/questions/347937/)**。 –