如何使用 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>
廣告