Create three random numbers and output if it is odd or not with nested function - Javascript Math

Javascript examples for Math:random

Description

Create three random numbers and output if it is odd or not with nested function

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head></head>
   <body translate="no"> 
      <input type="button" onclick="generateRandom()" value="Click me"> 
      <script>
function generateRandom() {/*from w  ww . j a  v a  2 s  . c o  m*/
  const a = Math.floor(Math.random() * 10);
  function isOdd(num) {
    return num % 2 == 1;
  }
  if (isOdd(a)) {
    console.log("odd")
  } else {
    console.log("even");
  }
}
    
      </script>  
   </body>
</html>

Related Tutorials