Home  >  Article  >  Web Front-end  >  How to return a random number between 1 and 200 using JavaScript?

How to return a random number between 1 and 200 using JavaScript?

王林
王林forward
2023-09-03 20:17:02631browse

How to return a random number between 1 and 200 using JavaScript?

To return a random number between 1 and 200, use the JavaScript Math.random() and Math.floor() methods.

Example

You can try running the following code to return a random number in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <script>
         document.write(Math.floor(Math.random() * 200) + 1);
      </script>
   </body>
</html>

The above is the detailed content of How to return a random number between 1 and 200 using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete