Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(foundations/variables and operators): add several examples and clarify a few points #27624

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: improve instructions on how to open the dev tools
  • Loading branch information
nikitarevenco committed Mar 17, 2024
commit 47f16e742b7984b964ffa1540778d87bcbd7ef28
16 changes: 12 additions & 4 deletions foundations/javascript_basics/variables_and_operators.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Introduction

In the previous sections you learnt how to structure webpages with HTML and style them with CSS. The next step is to make the webpage *interactive*, which is exactly what JavaScript is for.

Check failure on line 3 in foundations/javascript_basics/variables_and_operators.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Trailing spaces

foundations/javascript_basics/variables_and_operators.md:3:190 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md009.md

In this section, we will focus on the fundamentals of JavaScript and how you can use it to manipulate all the various interactions between the web page and user.

Expand All @@ -24,9 +24,11 @@

### How to run JavaScript code

All JavaScript we will be writing in the majority of the Foundations course will be run via the browser. Later lessons in Foundations and the NodeJS path will show you how to run JavaScript outside of the browser environment. Outside of these lessons, for now you should always default to running your JavaScript in the browser unless otherwise specified, otherwise you may run into unexpected errors.
All JavaScript we will be writing in the majority of the Foundations course will be run via the browser. Later lessons in Foundations and the NodeJS path will show you how to run JavaScript outside of the browser environment.

Check failure on line 27 in foundations/javascript_basics/variables_and_operators.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Trailing spaces

foundations/javascript_basics/variables_and_operators.md:27:226 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md009.md

The simplest way to get started is to create an HTML file with the JavaScript code inside of it. Type the basic HTML skeleton into a file on your computer somewhere:
Outside of these lessons, for now you should always default to running your JavaScript in the browser unless otherwise specified, otherwise you may run into unexpected errors.

The simplest way to get started is to create an HTML file with the JavaScript code inside of it. Use the VS Code snippet <kbd>!</kbd> + <kbd>TAB</kbd> to create the basic HTML skeleton in a file on your computer somewhere:

```html
<!DOCTYPE html>
Expand All @@ -44,9 +46,15 @@
</html>
```

Save and open this file up in a web browser (you can use ["Live Server" on Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) to do this!) and then <span id="access-devTools-console">open up the browser's console by right-clicking on the blank webpage and selecting "Inspect" or "Inspect Element". In the 'Developer Tools' pane find and select the 'Console' tab</span>, where you should see the output of our `console.log` statement.
Save and open this file up in a web browser and then open up the browser's console:

1. Right-click on the blank webpage or press <kbd>F12</kbd>.
1. Click on "Inspect" or "Inspect Element" to open the Developer Tools (redundant if you use the keyboard shortcut).
1. Find and select the "Console" tab, where you should see the output of our `console.log` statement.

**Tip:** You can use ["Live Server" extension in Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) to automatically update the browser when you save your file instead of having to manually refresh the page to see any changes when you edit your code. Try edit the text to say something different!

> <span id="console-log">`console.log()` is the command to print something to the developer console in your browser. You can use this to print the results from any of the following articles and exercises to the console.</span> We encourage you to code along with all of the examples in this and future lessons.
`console.log()` is the command to print something to the developer console in your browser. You can use this to print the results from any of the following articles and exercises to the console. We encourage you to code along with all of the examples in this and future lessons.

Another way to include JavaScript in a webpage is through an external script. This is very similar to linking external CSS docs to your website.

Expand Down Expand Up @@ -114,8 +122,8 @@
- [How do you increment and decrement a number?](https://javascript.info/operators#increment-decrement)
- [Explain the difference between prefixing and postfixing increment/decrement operators.](https://javascript.info/operators#increment-decrement)
- [What is operator precedence and how is it handled in JS?](https://javascript.info/operators#operator-precedence)
- [How do you access developer tools and the console?](#access-devTools-console)

Check failure on line 125 in foundations/javascript_basics/variables_and_operators.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Link fragments should be valid

foundations/javascript_basics/variables_and_operators.md:125:3 MD051/link-fragments Link fragments should be valid [Context: "[How do you access developer tools and the console?](#access-devTools-console)"] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md051.md
- [How do you log information to the console?](#console-log)

Check failure on line 126 in foundations/javascript_basics/variables_and_operators.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Link fragments should be valid

foundations/javascript_basics/variables_and_operators.md:126:3 MD051/link-fragments Link fragments should be valid [Context: "[How do you log information to the console?](#console-log)"] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md051.md
- [What does unary plus operator do to string representations of integers? eg. +"10"](https://javascript.info/operators#numeric-conversion-unary)

### Additional resources
Expand Down
Loading