Minesweeper - logging issue


Hi -
I’m having problems coding first minesweeper exercise


the task is to create the vertical lines in the board by printing the const blankline 3 times.

const blankline = ' |  | ';
console.log(`this is what an empty board would look like:`)
console.log({$blankline} *3);


console.log('blankline' *3);

I’ve tried many other lines of code - for about the past hour - nothing working. What am I doing wrong?


Hello :slight_smile:

JavaScript does not support multyplying strings. If you want to repeat something few times you can do this by hand (this method adds whitespace as separators):

console.log(blankline, blankline, blankline);

or you can use repeat method:


Reference -> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat

In JavaScript we don’t use $ to mark a variable.


Hi factoradic,

I’m supposed to print this when running minesweeper.js in terminal:

This is what an empty board would look like:

But the line console.log(blankline.repeat(3)); will print

this is what an empty board would look like:

I can fix the spacing of the pipes, but how to make the board print |

to 3 separate lines?

I’ll keep trying, but any advice?

Cecilia D.


Got it! - removed the semi-colon from the end of each line.
But why does that make a difference?


If your intention is to write a template literal, then the correct syntax (also taking into account aforementioned, .repeat) is,


To get the earlier example to work. write the newline escape token directly to your string constant…

const blankline = ' |  | \n';

then later,


To reduce the logging to a single statement…

const blankline = ' |   |\n';
console.log(`This is what an empty board would look like:\n${blankline.repeat(3)}`);
This is what an empty board would look like:
 |   |
 |   |
 |   |

Note the use of an embedded template literal containing the JavaScript expression.


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