Let’s dive right in!
Look through these now and then use them to test yourself after doing the assignment:
concatenationand what happens when you add numbers and strings together?
Total duration: 175 minutes
Part 1/3 – Duration: 68 minutes
Part 2/3 – Duration: 90 minutes
Part 3/3 – Duration: 14 minutes
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.
Study the following material and implement the concepts in your own web page:
Here is a neat trick to throw away those decimals from a number using the bitwise NOT operator. We suggest you forget the bitwise operators for now, as it is a rather advanced topic. Just keep this code snippet for whenever you want to quickly convert a floating point number to an integer and impress your fellow JS devs!
let float = 3.1415; let int = ~~3.1415; console.log( int ); // 3 console.log( ~~1234.5678 ); // 1234
Variables are pointers to "storage containers" for data in your code. You can think of variables as something close to your contacts in your mobile phone. Each contact list entry contains a name, e.g. Mary. This is your variable name. And each contact list name (variable name) points to a place in the memory of your mobile phone that stores a telephone number or address, e.g. 6985252114.
|VARIABLE NAME||POINTER TO||DATA IN MEMORY|
|Mary||— Points to –>||6985252114|
|Ahmed||— Points to –>||6971234567|
In much the same way, variables in programming languages, are names that point to some memory location in which some kind of data is stored:
var someVariableName = "Just some text."; // The someVariableName, now points to a place in memory // where the "Just some text." data is stored and can be retrieved.
The above tutorial mentioned this, but it’s important enough to note again:
var statements. Don’t let it bother you! There’s nothing inherently wrong with
var, and in most cases
let behave the same way. But sometimes the behavior of
var is not what you would expect. Just stick to
const) for now. The precise differences between
let will be explained later.
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:
console.log(23 + 97)into your html file)
(4 + 6 + 9) / 77
let a = 10
9 * a
let b = 7 * a(returns undefined) and then
maxwith the value
max - 13
actual / max
percentagein the console and press enter you should see a value like
const VAT = 24; // VAT Tax is set to 24% const phone = 300; // Net price const total = phone + ( phone * ( VAT / 100 ) ); // Total === net price + VAT
How about calculating a woman’s fertile window?
Blood alcohol content anyone?
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.
Click this link and follow the instructions on how to complete and submit this assignment.