【发布时间】:2016-05-19 00:42:23
【问题描述】:
我正在开发一个 JavaScript Hangman 游戏,我需要打印出与随机选择的单词长度相同数量的破折号。我已经这样做了,但它也会为句子中的空白打印一个破折号,那么我怎样才能忽略这些空格,只为句子中的字母打印一个破折号呢?任何帮助表示感谢。
这是打印破折号的代码
for(var i = 0; i < sayings[randomSaying].length; i++)
{
progress.innerHTML += "-";
}
随机变量
var sayings = [
"cash on the nail",
"charley horse",
"foul play",
"bury the hatchet",
"hands down",
"if the cap fits",
"mumbo jumbo",
"see red",
"stone the crows",
"thick and thin",
]
sayings.toString();
var randomSaying = Math.floor(Math.random()*sayings.length);
【问题讨论】:
-
随便选一个词还是一句俗语?
-
问题表明研究工作严重不足。这不是编码服务,您应该尝试自己研究基础知识
标签: javascript html string