Console.log exercises

Hi, I am struggling with exercise No. 8 - print with text formatting

when i follow the solution, console will not give me back values but only literally ${length} and ${width} in text.
Here are all 3 inserted lines:

var length = 10.101;
var width = 3.843;
console.log(‘the rectangle is ${length} cm long and ${width} cm wide’);

and result i got:

the rectangle is ${length} cm long and ${width} cm wide

what am I not understanding? ( iam completely new to programming:)

1 Like

Hi mate !
I just finish this one, actually i struggle a lot because characters seem to be the same but in fact they are not ( i struggled during 2 hours to make a “go to the line” command because i used “/” instead of “”
I copy you the way that worked for me, but i am too noob to explain you exactly why, maybe those " ’ " characters were not the same we both used for coding, i copied them from a code line on the following link

I hope i helped you :slight_smile:

My answer :
var length = “10.101”
var width = “3.843”
console.log(the rectangle is ${length} cm long and ${width} cm wide)


yeah, change of those ’ for ` helped!
dont even know how to name them:)


I’m stuck on the same problem. Even after changing my variable to string I get the same result.

var length = 1.101;
var width = 3.843;
console. log( The rectangle is $ {length} cm long and $ {width} cm wide.) ;
VM2033:3 The rectangle is $ {length} cm long and $ {width} cm wide.

1 Like

Hi @CC123,
The ${} syntax is applicable for the new syntax in javascript after 2015. It is called “Template Strings” in Javascript. They let you add variables in the string directly without + . It just a different way of writing strings. If you notice ,template strings make use of backticks instead of normal quotes.

Also, there shouldn’t be any space between the dollar sign and the curly brackets. That’s the mistake you have done.

For example –

Normal string syntax
console.log("my name is" + myVariable)
Template String
console.log(`my name is ${myVariable} `)

Hope this clears it out for you.

Happy Learning! :smiley:

Amazing thank you, I thought those were single quotation marks instead of backticks.

Here is my console result…not good for question 4
Whare did i go wrong?
Hello world=“hello world”
VM92:1 Uncaught SyntaxError: Unexpected identifier
var hello=“hello”;
var world=“world”;
console.log(hello+ " “+world);
VM296:1 hello world
var note=”!";
console.log(hello+ " " + world+note);
VM488:1 hello world!
var age=“age”;
var note 1=":";
VM572:1 Uncaught SyntaxError: Unexpected number
var noteb=“4”;
console.log(hello+" "+world+note / age+note 1+noteb);
VM808:1 Uncaught SyntaxError: missing ) after argument list
var age=“age”;
var old=“age:4”;
VM894:1 age
var age=67:
VM922:1 Uncaught SyntaxError: Unexpected token ‘:’
console.log(“myage”, age);
VM1002:1 myage age
console.log(“myageis”, age);
VM1086:1 myageis age
console.log(“my age is”+ age);
VM1171:1 my age isage
var age+99;
VM1199:1 Uncaught SyntaxError: Unexpected token ‘+’
var My age=“my age is”;
VM1255:1 Uncaught SyntaxError: Unexpected identifier
Console.log(my age+ age);
VM1325:1 Uncaught

Hi, where do you find those quotes on Mac?

Hi there.
In the exercise number 8 I have done this way:

var length = 10.101;
var width = 3.843;
console.log("The rectangle is " ,length, "cm long and " ,width, “cm wide.”);

is this way a wrong way?
It runs properly.

No, it is not. It is perfectly applicable.

1 Like

Hi @Jorenso,

Those quotes are called back ticks and they can be found on a mac as shown below. You shave to hold Shift and type the button.

Hope this helps.

1 Like

Thx! That helped a lot! :wink:

Hi! Could you help me with one more thing? How to do line break, when writing code in Crome browser…

This should do the trick - console.log("hi \nJorenso");

The \n will break the line.

1 Like