Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Basic practice code; Chrome Console not working

My code is not working in Chrome. Using VS Code The HTML code:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge">

<script src="JavaScript.js"></script>
<title>Document</title>

</head> <body> <script src="JavaScript.js"></script> </body> <html>

And the Javascript:

var hello = "Hello";

console.write("Hello");

Mike Hatch
Mike Hatch
14,940 Points

Do you understand the error message that Google Console gives you?

var hello = "Hello";
console.write("Hello");

Uncaught TypeError: console.write is not a function  at <anonymous>:3:9

What that tells you is the code that needs to be fixed is "write". I've a feeling you meant "document.write" or "console.log" instead.

3 Answers

DOH'! Yeah, very bad over sight on my part, I forgot about the file/folder liking code. Once I put in the correct code "<script type ="text/javascript" src ="js/js.js"/>" Every thing works as it should. TA'DA!! Thanks again for the help :)

Mike Hatch
Mike Hatch
14,940 Points

You're welcome. It's a battle.

Steven Parker
Steven Parker
221,292 Points

As Mike pointed out, there's no "console.write" function. But there are "document.write" and "console.log" functions.

The choice depends on what you want to do. The "document.write" will put the output onto the browser page, and "console.log" will show it in the JavaScript console.

Thanks guys! I just got it, I was not connecting the external JS file correctly. Just a simple oversight, I believe. And the wrong placement of the document.write, and console.log parts. Ooopsie! :) Thanks again for the help. :) Steven Parker and Mike Hatch