Hi everyone,

I need some help with Homework I have to create this rudimentary Minesweeper game where I have a HTML page with 100 buttons in a 10 x 10 Table with a value of '1' . My Question is , is there a more efficient method of generating a 100 button table like that without a whole bunch of lines of code?

5 Years
Discussion Span
Last Post by AleMonteiro

Something like this:

var numRows = 10,
    numCols = 10,
    strHtml = '';

for(var i=0; i < numRows; i++) {
    strHtml += '<tr>';
    for(var j=0; j < numRows; j++) {
        strHtml += '<td>1</td>';
    strHtml += '</tr>';

document.getElementById('MyTable').innerHTML = strHtml;

Edited by AleMonteiro


![thanks that pointed me in the write direction:

now I need a way to do the following which im sort of confused on:

  1. When the user clicks a button the number in that button gets distributed among its North, East, South, and West neighbors, with wraparound. For example, if the button has the number 2 button to the North will have its number increased by one, as well as the number to the East. The button that had the 2 will now have 0.
  2. There is a score button which always contains the number of zeroes in the game board.

I have attached the HTML side of the website now Im starting to work on the JS side and its number 2 and 3 Im having issue implementing

(/attachments/large/3/HW3_html_screenshot.PNG "HW3_html_screenshot")

thank you very much

Attachments HW3_html_screenshot.PNG 12.87 KB

Let's think about the table as an excel sheet, where the cells are A1, A2, B1, B2 and etc.

A1 is clicked (with value 1) A1 will become 0 and B1 will become 2.
B1 is clicked (with value 2) B1 will become 0, C1 will become 2 and B2 will become 2.

Is that right?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.