Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
See the solution for the Board and Space class constructor methods.
Template Literals
Template literals are an easier way to create a string that has embedded expressions, like a variable, for example.
Previously, you'd have to concatenate a string to a variable like this:
const name = "Ashley"
const newString = "Hello my name is " + name;
With template literals, you can do the same in an easier fashion. Template literals are enclosed in backticks instead of single or double quotes like a regular string. The embedded expression is wrapped in curly braces, and preceded with a dollar sign, right inside the string.
const name = "Ashley"
const newString = `Hello my name is ${name}`;
Solution Code
Board Class Constructor Method
constructor() {
this.rows = 6;
this.columns = 7;
this.spaces = [];
}
Space Class Constructor Method
constructor(x, y) {
this.x = x;
this.y = y;
this.id = `space-${x}-${y}`;
this.token = null;
}
You need to sign up for Treehouse in order to download course files.
Sign up