Look through these now and then use them to test yourself after doing the assignment:
- How do you declare a variable?
- What are three different ways to declare a variable?
- Which one should you use when?
- What are the rules for naming variables?
- What are operators, operands, and operations?
- What is concatenation and what happens when you add numbers and strings together?
- What is the difference between
- What are operator precedence values?
- What are the increment/decrement operators?
- What is the difference between prefixing and post-fixing them?
- What are assignment operators?
- What is the "Unary +" Operator?
- This variable tutorial will explain you everything you need to know! Be sure to do the Tasks at the end. Information won't stick without practice!
The above tutorial mentioned this, but it's important enough to note again:
varstatements. Don't let it bother you! There's nothing inherently wrong with
var, and in most cases
letbehave the same way. But sometimes the behavior of
varis not what you would expect. Just stick to
const) for now. The precise differences between
letwill be explained later.
Numbers are the building blocks of programming logic! In fact, it's hard to think of any useful programming task that doesn't involve at least a little basic math... so knowing how numbers work is obviously quite important. Luckily, it's also fairly straightforward.
- 1.This W3Schools lesson followed by this one, are good introductions to what you can accomplish with numbers in JS.
- 2.This MDN article covers the same info from a slightly different point of view. There's much more that you can do with numbers, but this is all you need at the moment.
Save and open this file up in a web browser and then 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, where you should see the output of our
console.log()is the command to print something to the developer console in your browser. Use it for all of the following exercises.
Try the following exercises:
- 1.Add 2 numbers together! (just type
console.log(23 + 97)into your html file)
- 2.Add a sequence of 6 different numbers together.
- 3.Print the solution to the following equation:
(4 + 6 + 9) / 77
- Answer should be approximately
- 4.Let's use variables!
- Type the following at the top of the script tag:
let a = 10
- Try the following:
9 * a
- and this:
let b = 7 * a(returns undefined) and then
- 5.You should be getting the hang of this by now... try this sequence:
- Declare a constant variable
maxwith the value
- Set another variable
max - 13
- Set another variable
actual / max
- If you type
percentagein the console and press enter you should see a value like
- 6.Take a few minutes to keep playing around with various things in your script tag. Eventually, we will learn how to actually make those numbers and things show up on the webpage, but all of this logic will remain the same, so make sure you're comfortable with it before moving on.
This section contains helpful links to other content. It isn't required, so consider it supplemental for if you need to dive deeper into something.