如何使用 JavaScript 返回介于 1 到 200 之间的随机数字?
若要返回介于 1 到 200 之间的随机数字, 请使用 JavaScript 的 Math.random() 和 Math.floor() 方法。
示例
您可以尝试运行以下代码以在 JavaScript 中返回 随机数。
<!DOCTYPE html> <html> <body> <script> document.write(Math.floor(Math.random() * 200) + 1); </script> </body> </html>
广告