如何在第 2 次和第 3 次(依此类推)单击 html 按钮时再次获得 运行 的功能?
How to get a function to run again on 2nd and 3rd (and so on) click of a html button?
我基本上只是想制作一个脚本,在单击按钮后抛硬币,其中 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;
}
if (foodNum = 1) {
应该是 (foodNum == 1) {
我基本上只是想制作一个脚本,在单击按钮后抛硬币,其中 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;
}
if (foodNum = 1) {
应该是 (foodNum == 1) {