当前位置: 动力学知识库 > 问答 > 编程问答 >

function - JavaScript Different Results?

问题描述:

I'm a bit new with JavaScript (learning from CodeCademy), and I was wondering why this was happening:

function Person(job, married) {

this.job = job;

this.married = married;

// add a "speak" method to Person!

this.speak = function()

{

console.log("Hello!");

};

}

var user = new Person("Codecademy Student",false);

user.speak();

I run this code in the CodeCademy interpreter, but it returns an error that states the following:

Oops, try again. It looks like 'Hello!' wasn't logged to the console. Make sure that you properly defined the method and that you didn't change any of the provided code.

However, my friend referred me to an online JavaScript console

https://repl.it/ (which actually has support for a lot of other languages too!), and it shows me that it is printing "Hello!"

I'm not very clear on why the website is doing this, or why it is different from the online console. I'm pretty sure I've double checked on making sure the code was the exact same...

网友答案:

The best place to learn javascript is in your browser's developer toolbar. If you are using Firefox, then download FireBug as an addon. Put your code inside the console and hit the run button. Or you can use any other browser to do the same. Just press F12 in any of the browser to open up the developer console.

分享给朋友:
您可能感兴趣的文章:
随机阅读: