18910140161

JS将单选按钮转换为算法参数

顺晟科技

2021-07-28 10:58:17

145

我做了一个简单的程序,为我的一门课生成一个NBA 2K21 MyPlayer的随机构建。用户单击的每个按钮都会为每个特征生成一个随机值。

我现在正在尝试修改程序,以记住用户输入的高度单选按钮,然后根据用户的选择生成一个随机位置。 我希望程序在以下之间随机设置:

pg/sg,如果高度在6'2“和6'5”之间,或 如果高度在6'5“到6'8”之间,则为SG/SF或 如果高度在6'8“和6'10”之间,则为SF/PF或 如果高度在6'10到6'11“之间,pf/c

最初该程序只有3个按钮,从数组中生成随机值,但现在它由3个按钮和用户选择的单选按钮组成。以下是我陷入困境之前的情况:

<h1>
 2k Archetype Generator
</h1>
<p>
  Choose Height
</p>
<form>

<input name="height" type="radio" id="h1"> 6'2"
<br>
<input name="height" type="radio" id="h2"> 6'3"
<br>
<input name="height" type="radio" id="h3"> 6'4"
<br>
<input name="height" type="radio" id="h4"> 6'5"
<br>
<input name="height" type="radio" id="h5"> 6'6"
<br>
<input name="height" type="radio" id="h6"> 6'7"
<br>
<input name="height" type="radio" id="h7"> 6'8"
<br>
<input name="height" type="radio" id="h8"> 6'9"
<br>
<input name="height" type="radio" id="h9"> 6'10"
<br>
<input name="height" type="radio" id="h10"> 6'11"
<br>

</form>
<br>
<button id="positionchoice" onclick="randpos()">
 Position
</button>
<p id="pos">

</p>      
<button id="primary" onclick="randprim()">
  Primary
</button>
<p id="no1">

</p>
        
<button id="secondary" onclick="randsecond()">
  Secondary
</button>
<p id="no2">

</p>
var p = document.getElementById("pos");
var skill1 = document.getElementById("no1");
var skill2 = document.getElementById("no2");
var height = ["6'2","6'3","6'4","6'5","6'6","6'7"
              ,"6'8","6'9","6'10","6'11"];
 var primary = ["Shot Creating", "Playmaking", "Defensive"
                ,"Sharpshooting","3-Point","Rebounding"];
        
var secondary = ["Slasher", "Finisher", "Shooter",
                 "Ball Handler","Lockdown", "Two-Way"];
        
var arr = ["PG", "SG", "SF", "PF", "C"];
                            
function randpos() {

}
        
function randprim() {
 skill1.innerHTML = primary[Math.floor(Math.random()*primary.length)];
}
        
function randsecond() {
 skill2.innerHTML = secondary[Math.floor(Math.random() * secondary.length)];
}

顺晟科技:

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航