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?

Recommended Answers

All 3 Replies

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;

![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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.