Using JavaScript in VS code

I feel like a total newb for asking this question, but I’ve googled and searched the forum for hours and can’t figure out the problem. So here it is:

I want to make a simple game using the Magic 8 Ball project as a base. So, I started by copying what I used to make the project into VS Code. I haven’t used JS in VS code yet, just HTML and CSS. I tried to run the program in VS code through the integrated terminal and I get the error message below:

I can’t figure out what I’m doing wrong. How do I get the code to run in VS Code? It ran perfectly here in the project workspace. So, I’m not sure if it’s my laptop, VS Code, or I’m just trying to do something I’m not supposed to because I’m new at this. Any advice is appreciated.


jscript does not seem to be the same as javascript:

well close, but not exactly the same. Maybe Jscript is stricter on the semi-colons? Anyway, i would just recommend you to use your browsers JS engine to make life easier for yourself

My understanding is that JScript is simply Microsoft’s implementation of JS, originally to avoid some copyright issues. The two ought to be the same, though I think there are some IE-specific extensions to JScript which aren’t present in “standard” JavaScript…

(It’s a bit like how there’s little variations in how you do things in SQL on a Microsoft DB or an Oracle one… unless they’ve both standardised themselves since I last went near Oracle…)

The error is pretty clear on the matter; you’re missing a semi-colon at line 1, char 5.

If you’d also posted the code, we’d be able to check whether the error is right or not. :slight_smile:

I understand where the error is and how to fix it. That was actually the first thing I tried, but then it gave me about 6 more before I stopped trying and when I looked back at the code, it didn’t make sense anymore. Here’s the code without the changes:

let userName = ’ ';

userName ? console.log('Hello, ’ + userName + ‘!’) : console.log(‘Hello!’);

let userQuestion = ‘Am I Pretty?’;

console.log(User asked: ${userQuestion});

const randomNumber = Math.floor(Math.random() * 8);

let eightBall = ‘’;

switch(randomNumber) {
case 0:
eightBall = “It is certain”;
case 1:
eightBall = “It is decidedly so”;
case 2:
eightBall = “Reply hazy try again”;
case 3:
eightBall = “Cannot predict now”;
case 4:
eightBall = “Do not count on it”;
case 5:
eightBall = “My sources say no”;
case 6:
eightBall = “Outlook not so good”;
case 7:
eightBall = “Signs point to yes”;
eightBall = “When Pigs Fly”;

1 Like

Code with changes:

let ;userName = ’ ';

userName ? console.log('Hello, ’ + userName + ‘!’) : console.log(‘Hello!’);

let ;userQuestion = ‘Am I Pretty?’;

console.log(User ,asked, {userQuestion:});

I stopped after userQuestion because it gives an “expression needed” error and I have no idea what that means


I’m going to go out on a limb and say it’s some oddity around Visual Studio Code, rather than your program…

Mainly because if I run the code (the unaltered version you posted first) in the Firefox dev tools console, it’s fine.

I guess you’re using Visual Studio Code to write the JavaScript file itself - but how are you running it? Are you using an option directly in VSC, or doing something else? :slight_smile:

I think you’re right. I am using the terminal in VSC which is an option directly from the code editor. I thought it would be easier than switching screens, but apparently not.

1 Like

I don’t do any dev stuff on my Windows machine, purely because there’s fewer hoops to jump through on Linux to get everything I need working, so I’m probably not the best guinea pig for this.

In any case, when I try and use VSC to run a JavaScript file I get a prompt about missing runtimes.

Another of the Super Users (who’s a tad busy elsewhere, so can’t reply directly) has pinged me a message suggesting that it may be that your JavaScript interpreter doesn’t understand let

If you use Chrome as your preferred browser, there is an extension available for Visual Studio Code called Debugger for Chrome. It basically lets you write the code in VS Code, but run it (and debug it) directly in Chrome using their JS interpreter.

If you’ve got Chrome installed, that extension might make it easier for you to write and run your JS locally. :slight_smile:

1 Like

I found the extension and that works like a charm. Thanks for the help it is greatly appreciated :smiley:


Excellent. :+1:

Glad we could help. I have honestly no idea what Visual Studio Code was using to run the code originally to give you those errors, but if the Chrome extension works then happy days. :grin:

I think windows users easily get the impression that a text editor is the operating system, is the thing responsible for running code.

It’s a text editor. Types letters, saves files. Doesn’t run programs.

The program you would use to run javascript code with is node, chrome, or firefox.

Imagine if every program had a built in web browser just so you could google without alt tabbing.

The same principle applies to programming in general, if a problem is multiple subproblems and you try to solve them all at once in the same place then you’ll get a complicated entangled piece of code, but if you solve one subproblem at a time in isolation from the rest then you’ll have several simple pieces.

The equivalent of double clicking a text file, at which point “file association” (such a silly thing) takes over.

If you ever peek at windows processes you might notice shost.exe using cpu for seemingly no reason (could be anything), well it’s that blob that got invoked.

Yeah, I was being a dumb dumb. VSC has so many features I got it in my head I could do anything on it smh. I figured out how to use the chrome debugger, which is helpful, but it wasn’t what I was originally trying to do. I thought I could use the terminal in VSC like the console in codecademy workspace :woman_facepalming:. I’m now using jsbin as I work through the JS side of my little game to run it in their console like I did here. Then running the debugger in VSC to make sure all the pieces fit together properly. So far so good :grinning:

It def was, before I created this post I was looking into what that was and trying to see if I could change it or something. I was doing the most smh. It worked out though, and thanks again to everyone for the help!

You’re not entirely wrong, but nearly all of it will be a wrapper around some other tool. vsc’s representation of those tools is incomplete so things can go wrong that vsc doesn’t deal with or you may need things that aren’t part of the representation - and then you have to deal with them directly without any help. It’s also not really vsc doing it, but whatever plugin you happen to be using.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.