Fill random value to an array - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Fill random value to an array

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head></head>
   <body translate="no"> 
      <script>
      const getRandom = () => Math.floor(Math.random() * 10) + 1;

const ask = () => {//from w  w w  . j  a  va  2  s .  c o  m
    const numbers = [getRandom(), getRandom()].sort((a, b) => b - a)
    console.log( numbers[0] - numbers[1] ? 'Right!' : 'Wrong!');
}

for (var i = 0; i < 6; i++) {
    ask();
}
    
      </script>  
   </body>
</html>

Related Tutorials