JScript Errors with console.log


#1

Hey ppl. I have looked everywhere on the internet and haven’t found an answer to my simple question. I’m trying to write some javascript code and have it print to the command prompt window on my computer (windows 7). I’m using Notepad++ and saving it as a .js file. When I run the code, it says

‘Script: C:\Users\me\Desktop\test.js
Line: 6
Char: 1
Error: Object expected
Code: 800A138F
Source: Microsoft JScript runtime error’

This is my code:

var test = true;


switch (test) {
case true:
console.log('yay it worked!');
break;
case false :
console.log('aww. it didnt work.');
break;
default:
console.log('Invalid answer');
}

What do I replace console.log with? I asked a friend but he didn’t have time to explain. He said something about ‘write To(console)’ or something. Idk. Just trying to figure it out so I can test javascript outside of HTML or codecademy. Thanks in advance! -matthew


#2

Script is the Microsoft dialect of the ECMAScript scripting language specification.

so you will need to google what you need for Jscript, which isn’t identical to javascript

if you want to run javascript, install nodeJS


#3

So JScript and Javascript are different. what do I replace console.log with to print it to the terminal then?


#4

well, there are not completely different:

i have no idea, never used Jscript, but this should be findable with a simple google search?

you need to make a choice: learn Jscript or switch to javascript

If you are going to use Jscript, you will need to learn it, in this process you should be able to find out what to use instead, maybe the whole switch statement is different? Maybe you can google already? I have no idea about Jscript.


#5

Ok. I still haven’t found the answer. Maybe someone who knows JScript can reply? that would probably help


#6

i think very few people here know Jscript, jscript seems to have a print function:

https://msdn.microsoft.com/en-us/library/9za221bh(v=vs.100).aspx


#7

I tried that and I got the same Error as before


#8

have you verified that switch even exist within Jscript? I think you are better of finding someone on stackoverflow who can help you with this, then here on the forum

it seem to exist:

https://msdn.microsoft.com/en-us/library/e240yzs4(v=vs.100).aspx

but there isn’t a single example i can find, good documentation this language (not)


#9

Yes. Switch works in JScript. JScript is a variant of JavaScript. So they are quite similar. Thanks for your help.


#10

you should go to stackoverflow, better change to find someone who knows Jscript then here.


#11

Ok. Sounds good. Thanks for your help.


#12

why do you decide to use Jscript? its far less commonly used, why not install nodeJS and use JavaScript which is far more common?


#13

I want to try and practice coding with the programs I have. I don’t want to get new ones just to test out things I know. I want to learn more and challenge myself.


#14

You don’t have to get new ones? Js can be run in browser (which i assume you have installed :wink: ), and open a console window (build into the browser), there console.log() output is displayed, but you would need to create html file, but no new software needs to be installed

then you have Javascript (which has far better documentation and more information (Q&A on stackoverflow for example)), going for a more obscure dialect (Jscript) is a major sacrifice.


#15

How do I open the command window in the browser?


#16

This depends on the browser, you must be able to find this with google

you might be even able to code in there


#17

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