Javascript Array store frequency of Dice Rolling

Description

Javascript Array store frequency of Dice Rolling

let face; //  w  ww .j  a v a 2s  .co m
let frequency = [ , 0, 0, 0, 0, 0, 0 ]; // leave frequency[0] 
                                        // uninitialized

// summarize results
for ( let roll = 1; roll <= 6000; ++roll )    
{                                             
   face = Math.floor( 1 + Math.random() * 6 );
   ++frequency[ face ];                       
} // end for                                             

// generate entire table of frequencies for each face
for ( face = 1; face < frequency.length; ++face )      
   console.log( face + ":" + frequency[ face ] );              



PreviousNext

Related