【发布时间】:2021-09-06 03:55:31
【问题描述】:
我试图基本上只是制作一个脚本,在单击按钮后翻转硬币,其中 0 = 泰国菜和 1 = 越南菜。随机数总是为 1(泰国菜 一些理由)。当我单击按钮时,它不会不断变化。会很感激 作为初学者的任何帮助谢谢!
<h1> What's it going to be? </h1>
<input type="button" id="random" value="Your food awaits" onclick="foodPicker()" >
<h3 id="food"> </h3>
function foodPicker(){
let foodNum = Math.floor(Math.random() * 2)
let result = ''
if (foodNum = 1) {
result = 'Thai';
}
else {
result = 'Viet';
}
document.getElementById('food').innerHTML = result;
}
【问题讨论】:
标签: javascript html function button