Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Add a conditional statement that tests if the value in variable a is greater than the value in variable b. If it is, log

im stuck

Wojciech Lehmann
Wojciech Lehmann
11,682 Points

Hi there,

const a = 10;
const b = 20;


if ( a > b) {
  console.log("a is greater than b");

} else {
  console.log("a is not greater than b");
}

1 Answer

You can use Template Literals. This page from MDN goes into a more detailed explanation, but here's an example:

const a = 10;
const b = 20;


if ( a > b) {
  console.log(`${a} is greater than ${b}`);

} else {
  console.log(`${a} is not greater than ${b}`);
}

When you use the backticks, anything you wrap in ${} will evaluate as an expression. ex.

console.log(`${1+3}`) 

would log 4 to the console, and

console.log(`${variable}`)

would log the contents of variable to the console.

Mod Edit: Changed comment to answer so it may be voted on or marked as best.