I'm having trouble generating 10 random integer from 1-100 on a mousedownevent. Also I need to display each in a table row, I'm a new to computer programming and I don't know what the mistake that I am committing.
Here's my code:
function process() {
'use strict';
var ara = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var index;
var output = '<tr>';
for (var i = 0; i < 1 0; i++) {
index = Math.floor(Math.random() * 100);
output += '<td>' + ara[index] + '</td>';
}
output += '</tr>';
document.getElementById('numbers').innerHtML = output;
}
function init() {
'use strict';
document.getElementById('showarray').onmousedown = process;
} // End of init() function
window.onload = init;
The Id numbers is a table tag and the id show array is the H3 tag I have to click to get the 10 integers
and here's the HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>assignment2.html</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<!-- assignment2.html -->
<h2>10 Random Integers from 1 to 100</h2>
<h3 id='showarray'>Mouse down here to show integers in table below</h3>
<table id="numbers" border="2"></table>
<span id="show5th">The fifth element is ?</span>
<script src="js/assignment2.js"></script>
</body>
</html>
jsfiddle with 10
and innerHTML
fixed