Created
July 5, 2018 01:18
-
-
Save LetsGetItDone/254fbdd9b2a0926c1bc8f2a31a38a0e4 to your computer and use it in GitHub Desktop.
board is not adding " | " <pipes> to array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const generatePlayerBoard = (numberOfRows, numberOfColumns) => { | |
let board = []; | |
for (var i = 0; i < numberOfRows; i++) { | |
let row = []; | |
for (var j = 0; j < numberOfColumns; j++) { | |
row.push(' '); | |
} board.push(row); | |
} | |
return board; | |
}; | |
const generateBombBoard = (numberOfRows, numberOfColumns, numberOfBombs) => { | |
let board = []; | |
for (var i = 0; i < numberOfRows; i++) { | |
let row = []; | |
for (var j = 0; j < numberOfColumns; j++) { | |
row.push(null); | |
} board.push(row); | |
} | |
let numberOfBombsPlaced = 0; | |
while (numberOfBombsPlaced < numberOfBombs) { | |
let randomRowIndex = Math.floor(Math.random() * numberOfRows); | |
let randomColumnIndex = Math.floor(Math.random() * numberOfColumns); | |
board[randomRowIndex, randomColumnIndex] = 'B' | |
numberOfBombsPlaced++; | |
// The code in your while loop has the potential to place bombs on top of already existing bombs. This will be fixed when you learn about control flow. | |
} | |
return board; | |
}; | |
const printBoard = board => { | |
console.log(board.map(row => row.join(' | ')).join('\n')); | |
} | |
console.log(generateBombBoard(3,3,2)); //BDD a bomb board is create with "null" values; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment