Generate random identical object

Viewed 100

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function init(){
  var resArr = [];
  for (var i = 0; i < 10; i++) {
    var obj = new Object();
    obj.q = getRandomInt(3,5);
    obj.r = getRandomInt(1,10);
    resArr.push(obj);
  }

  var str = '<table border=1><th>Multiplication</th>';
  for (var i = 0; i < resArr.length; i++) {
    str+='<tr><td>'+resArr[i].q+' * '+resArr[i].r+' = '+(resArr[i].q *resArr[i].r)+'</td></tr>';
  }
  str += '</table>';
  document.getElementById('multiTable').innerHTML = str;
}
init();
<button type="button" name="button" onclick="init()">Refresh</button>
<div id='multiTable'></div>

Here I am generating random object and pushing to an array. I am really stuck how to check that created object is present or not in array.

I want to generate random number to show in multiplication table.

3 Answers
Related