Creating a game board - minesweeper


My code for creating a game board is printing the game board with the line ‘undefined’ at the bottom:

CeciliaertysMBP:src ceciliadougherty$ node minesweeper.js
Current board:
| |
| |
| |

I’m writing the code based on lesson. Below is the code I wrote in minesweeper.js. Why is this printing ‘undefined’ in the console?

const printBoard = board => {
console.log('Current board: ‘);
console.log(board[0].join(’ | ‘));
console.log(board[1].join(’ | ‘));
console.log(board[2].join(’ | ‘));
const board = [
[’ ', ’ ', ’ ‘],
[’ ', ’ ', ’ ‘],
[’ ', ’ ', ’ ']



undefined is the default returned value of a function, by calling console.log on your printBoard function call you log the returned result (which is undefined) of printBoard function


I wish I understood what you are talking about, but I honestly can’t say
that I do understand.
The default value of a function is undefined. Even after you give it a
value? I thought ‘const board = board => …’ gave it a value.
Or is it because a function is not a variable.
Ok, a little more confused now.


this is different:


returned is key here, function always have to return a value. So undefined is the default returned value

to log the returned result you need to call console.log() on printBoard function call, which you do here:


but do you want to log the returned result?


Ok. thank you. It’s becoming a little clearer now. I appreciate your


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.