var width = 3.843;
undefined
var length = 10.101;
undefined
console.log(“the rectangle is ${length} cm long and ${width} cm wide.”);
I can’t get the output to say the actual numbers… any suggestions on what I’m doing wrong?
var width = 3.843;
undefined
var length = 10.101;
undefined
console.log(“the rectangle is ${length} cm long and ${width} cm wide.”);
I can’t get the output to say the actual numbers… any suggestions on what I’m doing wrong?
In order to add variables into your output string use + like this:
console.log("the rectangle is " + length + " cm long and " + width + " cm wide.");
Result in console:
the rectangle is 10.101 cm long and 3.843 cm wide.
Thanks, I’ll try that. I had to go to solutions to see why what I was doing wasn’t working and that’s the solutions that was given. Don’t know why it still didn’t work, and was/am not familiar with the ${} yet…
I see you are trying to use template-strings. In this case, you would not use double quotation marks " " but these single ones
instead. Unfortunately they are not shown here in the forum post because they are used for Preformatted text. lol. Try:
console.log(the rectangle is ${length} cm long and ${width} cm wide.
); and use the quotation marks you can see here in the console.log command:
Note that with template-strings you can also print for example with row breaks like this:
console.log(the rectangle is ${length} cm long and ${width} cm wide.
);
and can insert variable values directly into the output without having to close and reopen the quotation marks.
So this will give you more control over the way the output will be displayed.
Ah I see. I don’t even know where to find the single quotation marks on my keyboard. They don’t look the same as the “apostrophe”. Thanks
You are welcome
On my keyboard (european, german layout) there are 3 possible single apostrophes, just try all of them until you find the one needed. Coding is often trial and error