简体   繁体   English

JavaScript随机希腊字母不起作用

[英]JavaScript-Random Greek Letters Not Working

So I have this absolutely fantastic javascript random stuff generator, except for one thing. 因此,除了一件事之外,我有这个绝对很棒的javascript随机数生成器。 You see, I have it set so that if it brings up a certain random value, it throws in a Greek letter too. 您会看到,我对其进行了设置,以便如果它调出某个随机值,它也会抛出希腊字母。 It worked great until I worked on it some and now that part is broken. 效果很好,直到我对此进行了一些处理,现在该部分已损坏。 The rest of it works, but that one part is necessary for it to make sense to those using it. 它的其余部分都可以工作,但是只有一部分对于使使用它的人有意义。 Here is the code: 这是代码:

<div id="unitInfo"></div>

<script type="text/javascript">
var pre = ["Research", "Storage", "Containment", "Mobile", "Biological", "Armed",     "Dimensional", "Reliquary"];
var types = ["Command", "Site", "Sector", "Area", "Unit", "Task Force"];
var greek = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta",     "Iota", "Kappa", "Lambda", "Mu", "Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", "Tau",     "Upsilon", "Phi", "Chi", "Psi", "Omega"];
var update = ["online", "offline", "classified", "under repair", "experiencing     containment breach", "under attack", "[CONNECTION SEVERED]", "[DATA EXPUNGED]",     "terminated", "rogue", "secure", "secure", "secure", "secure", "secure", "secure",     "secure", "secure", "secure", "secure", "secure", "secure", "secure", "secure", "secure",     "secure", "secure", "secure", "secure", "secure", "secure", "secure", "secure", "secure",     "secure", "secure", "secure", "secure", "secure", "secure", "secure", "secure", "secure",     "secure", "secure", "secure"];

var info = pre[Math.floor(Math.random() * pre.length)];
    info += " " + types[Math.floor(Math.random() * types.length)];
if ( types == "Task Force" )
{
    info += " " + greek[Math.floor(Math.random() * greek.length)];
    info += "-" + ( 1 + Math.floor(Math.random() * 50) );
    info += " is " + update[Math.floor(Math.random() * update.length)];
}
else
{
    info += "-" + ( 1 + Math.floor(Math.random() * 50) );
    info += " is " + update[Math.floor(Math.random() * update.length)];
}
document.getElementById("unitInfo").innerHTML = info;
</script>

The info picks from pre and hence can never be "Task force" , so the info += greek[...] part of the if branch is never triggered. infopre那里挑选出来的,因此永远不能成为"Task force" ,因此,永远不会触发if分支的info += greek[...]部分。


May be this is what you want - 可能这就是您想要的-

var info = types[Math.floor(Math.random() * types.length)];

if ( info == "Task Force" )
{
    info = pre[Math.floor(Math.random() * pre.length)] + " " + info;
    info += " " + greek[Math.floor(Math.random() * greek.length)];
    info += "-" + ( 1 + Math.floor(Math.random() * 50) );
    info += " is " + update[Math.floor(Math.random() * update.length)];
}
else
{
    info = pre[Math.floor(Math.random() * pre.length)] + " " + info;
    info += "-" + ( 1 + Math.floor(Math.random() * 50) );
    info += " is " + update[Math.floor(Math.random() * update.length)];
}

PS. PS。 Very cool selection of words. 非常酷的单词选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM