Something is wrong with $ symbol and curly bracket {} that cause error when I run code though syntax is correct

Hi, :woman:

I’m newbie to code. I am learning JavaScript and practicing exercise in Methods for JavaScript from Codecademy’s course menu.

When I run code by practising examples of String.methodName() by typing examples of syntax from MDN Web docs on the panel of app.js by Codecademy, I get error if the syntax include the $ symbol and {} even I typed the syntax correctly and exactly . If I copy the same syntax from examples from MDN Web docs and paste on the panel of app.js by Codecademy, and run the code. As a result, the code run well without errors. The methodName (string.methodName) doesn’t change into blue color if the syntax follow after with $ and {}, the $ symbol and {} symbol don’t change into white color as they are supposed.)

I also have the same problem when I run code from Visual studio Code. I assume that something wrong with $ and {} are problem that cause error.

( I am using norwegian laptop keyboard. I type alt gr + 4 for $ symbol and alt gr + 7 for { and alt + 0 for } ).

Here’s one of examples which I am having problem. It runs well if I copy the console.log…from MDN Web docs and paste on app.js by Codecademy but if I type exactly the same syntax on app.js. I get error.

const sentence = 'I learn to code';

const index = 6 ;

console.log(`The character at index ${index} is ${sentence.charAt(index)}`);

Can anyone know the solution to my problem? Thank you in advance.
Happy coding everyone! :smiley_cat: :keyboard:

There’s no backticks ``` surrounding the contents of your console.log(). When using string interpolation, you have to use backticks instead of quotation marks.

1 Like

Hi , thank you for your feedback.

As I am new to learn code and still don’t know much about coding by using in both many different methods or function but I also think the same like you, there should not be backticks ’ ’ surround console.log() .
As I explained in my post, I copied this syntax from MDN Webs docs and the code runs well without error when I run it on the working panel of app.js by Codecademy . But if I type exactly the same syntax on the working panel and run it, it displays error.
I am wondering whether backtick must be written in side brace () of console.log() when console.log() includes a string.method (for example .charAt method and you can see it in the syntax of my post).

Anyway, I guess I will discover more in the future how write correct syntax or why some symbols don’t work when I run code though syntax is correct when I learn more .
Thanks again :cupcake: and happy coding. :smiley_cat:

I copy pasted the code in your original post to an online js editor and it worked fine. The output in the console was The character at index 6 is n.
I don’t see any syntax problems with your use of backticks `` or with $, { }

To me, it appears that your problem might be related to AltGr.
In VSCode, when you press AltGr + 4, does the $ symbol appear on screen? What about the curly braces { }?

There were no backticks when she first posted.

1 Like

Hi again,
Sorry that I read your response fast therefore I misunderstood your comment about backticks regarding the syntax in my post. Now I understand you meant that there should be backtick…I thought you meant there should not be backtick surround the content of console.log… :grinning: that’s why I thought backtick might be another problem beside {} symbol and $ symbol.
Anyway, Thanks again for your input. :strawberry:
:smiley_cat: :keyboard:

Hi, :woman:
Earlier, I tried to respond your comment and have sent it but now I see that it does not display my response here. Something must went wrong but now I try again. Thank you for your input.

After reading your feedback, I have tried to run one syntax on VSCode from another tutorial and I pressed AltGr + 7,0 for {} and it works. Before it did not work because I copied {} symbol and $ symbol from Character Map App on Window Start Menu and pasted it on VSCode. I have not tried with $ symbol on VSCode yet by pressing AltGr + 4 as I can not find again the example of the syntax that uses $ symbol. But now at least I know ALTGR + 7,0 for {} symbol work when I run the code.

I also got the same output as yours regarding the syntax from my fist post ( The output in the console was The character at index 6 is n .). As I mentioned in my post that the syntax runs well if I copy it from MDN Webs Docs and paste it on the working panel of app.js from Codecademy but if I type exactly the same syntax and press AltGR + 7, and +0 for {} symbol, it only displays error.

Hopefully I can find out how to make {} and $ work on app,js from Codecademy.
Thanks again and enjoy coding! :cake:
:smiley_cat: :keyboard:

1 Like

I don’t know if your laptop keyboard has a number pad (many laptops don’t have it).

If your keyboard has a number pad, then pressing ALT (Not AltGr) and entering number codes can create the symbols

ALT + 36  // $
ALT + 123 // {
ALT + 125 // }

This is pretty tedious.

Hopefully you find a solution which works.

I think your tip for ALT (not Alt Gr) is useful :+1: and it would be great if this is applied on keyboard has a number pad like you have mentioned.
I have tried your suggestion on my keyboard but it does not work. Scandinavian keyboard is a little complicated to use in some cases, I think.
Ealier I tried to type again the same syntax that including both $ and {} on app.js. It’s still not working.
The color of both $ and {} are supposed to be white color but they are yellow color. $ and {} don’t work if they lie inside tickback ’ '.

Thanks again :chocolate_bar:

Just out of curiosity, how do you type a backtick on a Scandavian keyboard?

I ask because a backtick is ` whereas in your last post you have ’ ’

If I am not mistaken, on a Scandavian keyboard, the backtick is produced by:

Just checking whether the issue is with the backtick or not.

I only press the keyboard which has backtick symbol ’ ’ without pressing either shift or alt.
Actually , I don’t know much about Scandinavian keyboard. I am using laptop Norwegian keyboard.


Perhaps you are picking the wrong symbol.

Try pressing the shift key + the key next to backspace and then the spacebar.

1 Like

Hi again, :woman_technologist:

You are genius! :clap: You have solve my problem :grinning:
I have tested the same syntax and use the backtick next to backspace (by pressing shift + the key next to backspace) as your instruction and the code ran well without error. :grinning:

Now I can come to a conclusion that using wrong backtick on the keyboard not only causes error when I ran the code (even the syntax was written correctly) but also change the colour of $ symbol and {} symbol from white to yellow. The right colour for $ and {} are white colour.

Since I started to learn to code, I used to use backtick by pressing the key next to Enter which has both * symbol and ’ ’ symbol (this backtick symbol ’ ’ look quite identical to the backtick from your instruction and it worked well in many syntax except the syntax which includes $ symbol and {} symbol. I never type ՙ ՚ symbol as you thought as there’s no such this symbol from my keyboard.

Anyway, thank you very much for your kindness to research my technical issue for helping me out. :coffee: :custard:
Whatever tech journey you are taking, I wish you a lot of success. :sparkles:

Happy coding :smiley_cat: :keyboard:

1 Like