Assessment wanted MDN first steps: Strings 4

Hi, I really appreciate your guidance please assess. I got a result, but is it the correct result?

Strings 4

CodePen

Thank you

Hi @thomjavare!

I’ve looked over your code, and you have done this perfectly; well done! In fact, I think your version is slightly better than our solution - I had forgotten about the exponentiation operator :wink:

Thanks again @chrisdavidmills, your feedback a great motivator.

But, does this get easier?

Yes, definitely. To begin with, programming seems super difficult because you don’t have previous knowledge of the different patterns you’ll encounter, and you kind of have to solve the same problem over and over again. But after a while, you’ll start to find patterns familiar, and think “oh yes, I’ve solved this problem before!”

One of the main skills is to get good at searching for things online. You’ll start to recognise the patterns, but you’ll never remember all of the exact syntax you need! Even professional programmers have to look things up every day.

That is very good news. I will have to come back to this message many more times in the future, that’s for sure. :metal:

Hi @tobias.wullschleger. Basically this just means updating your string value from using regular quotes, e.g.

let string = 'I am a string';

to using backticks, e.g.

let string = `I am a string`;

The advantage of using template literals is that they are much cleaner than regular string literals, for example instead of having to break up and concatenate if you want to insert another value, like this:

let myNumber = 3;
let string = 'My favorite number is ' + myNumber + '. I really like it!';

You can insert variables inside special ${} syntax, e.g.

let myNumber = 3;
let string = `My favorite number is ${myNumber}. I really like it!`;

These special variable insertions can also contain expressions, not just variables, e.g. ${myNumber + 2}, whatever you like really.

See also here for a write up of the basics.

2 Likes