Need help with problem in JavaScript

Hi, I am new to coding and I am practicing to get more comfortable with each topic in JavaScript.

Sometimes when I type out multiple values in a ‘console.log()’, the quotation marks (’ ‘, " ", , included) would highlight the wrong part of code. In the topic ’ Advance Objects: 7. Factory functions’, . the code:

const robotFactory = (model, mobile) => {
return {
model: model,
mobile: mobile,
beep() {
console.log(‘Beep Boop’);

const tinCan = robotFactory(‘P-500’, true);

works completely fine. However if you wanted to change ‘true’ as a string (const tinCan = robotFactory(‘P-500’, ‘true’). This will highlight the closing bracket as the string, and the colour of ‘true’ changes to purple. I don’t understand how this works, and this happens when you also add more values. Please help, thank you :grin:

Hello, and welcome to the forums!

The syntax highlighting in the learning environment isn’t perfect. Sometimes what you’re describing means there is an error in another part of the code above, such as a missing curly brace, bad semi-colon placement, out of place parenthesis, etc. etc. However, I’ve also found there are some false-positives, especially when an arrow function is nearby.

Using your code as an example::

with arrow function

without arrow function

This is just one example of the syntax being thrown off. There are probably more but this is the most common one I’ve found. To be clear, I’m not advocating you switch back to the old way of declaring functions, just be conscious of potential syntax highlighting issues so they don’t eat up your time for working code.

1 Like

Hey @selectall, thank you so much for that! That does really help, I never knew something like that would affect the syntax like that. I practice my coding on the review for each lesson, creating similar codes but in my own words and style so it’s easier for me to memorize and be comfortable with each technique. This also helped me fixed my own code in the review :grinning_face_with_smiling_eyes: I didn’t want to be stuck on it while the problem persisted for too long, so I had to rewrite my code another way for it to work. However now I know to be aware things such as the arrow functions or even little details such as bad semi-colon placement. Thank you very much @selectall! :grin:

1 Like