In Javascript, the console is the place where the code is managed. You can log a message to the console, and any errors that the code presents will appear here as well. In order to log something to the console, you should type console.log('message');. Of course, replace message with your message of choice. In this case, the expected output would be message.
One thing that would be important to note is the semicolon at the end of the line. Every javascript command will end in a semicolon, with very few exceptions, which we will cover later in this topic. In theory, 100% efficient javascript would have no linebreaks and almost no spaces, but this is very hard to read and debug. Generally, you would put a linebreak at the end of each command.
There are many other commands that you can give to the console which we will cover later in this course.
There are a few ways to run a javascript program:
1. Run an HTML file:
Follow the steps in the Javascript introduction to make a new project. Then, open the project folder and run the 'index.html' file. If it opens a text editor like atom, right click it and click 'open with' and then your browser.
2. Use a web editor:
Open the p5 javascript editor and delete what is currently in the project. Type your code there and click the play button. If you want to save your projects, you will need to make an account. This is the method I will be using to share all of the examples used in this post, so I suggest that you give it a try. However, I would recommend using option 1 for larger projects.
3. Type it in the console:
This is more useful for running smaller commands and debugging your program. Different browsers and operating systems will have different ways to access the console, but giving it a quick google search should be enough.
CHALLENGE: Make a program that logs your name to the console.
I will post all of the solutions to this course once everything is completed.
If you have any questions, let me know in the comments section
- Noah
One thing that would be important to note is the semicolon at the end of the line. Every javascript command will end in a semicolon, with very few exceptions, which we will cover later in this topic. In theory, 100% efficient javascript would have no linebreaks and almost no spaces, but this is very hard to read and debug. Generally, you would put a linebreak at the end of each command.
There are many other commands that you can give to the console which we will cover later in this course.
There are a few ways to run a javascript program:
1. Run an HTML file:
Follow the steps in the Javascript introduction to make a new project. Then, open the project folder and run the 'index.html' file. If it opens a text editor like atom, right click it and click 'open with' and then your browser.
2. Use a web editor:
Open the p5 javascript editor and delete what is currently in the project. Type your code there and click the play button. If you want to save your projects, you will need to make an account. This is the method I will be using to share all of the examples used in this post, so I suggest that you give it a try. However, I would recommend using option 1 for larger projects.
3. Type it in the console:
This is more useful for running smaller commands and debugging your program. Different browsers and operating systems will have different ways to access the console, but giving it a quick google search should be enough.
CHALLENGE: Make a program that logs your name to the console.
I will post all of the solutions to this course once everything is completed.
If you have any questions, let me know in the comments section
- Noah
Comments
Post a Comment