Minesweeper - logging issue


#1

Hi -
I’m having problems coding first minesweeper exercise

https://www.codecademy.com/courses/minesweeper/projects/create-project?program_content_id=6f7662b206ec6e765f191db1e9611bac&program_id=ddc2e30ea7a6899092d659452f03f6af

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);

or

console.log('blankline' *3);

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


#2

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:

console.log(blankline.repeat(3));

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.


#3

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?

thanks!
Cecilia D.


#4

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


#5

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

console.log(`${blankline}\n`.repeat(3));

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

const blankline = ' |  | \n';

then later,

console.log(blankline.repeat(3));

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.


#6

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