Javascript examples for Math:random
Create three random numbers and output if it is odd or not with nested function
<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>