Tutorial 01
-
Find out how you can open the Developer Tools on your browser.
-
Open up some of your favorite webpages and using your Developer Tools, disable JavaScript and see what happens to the page. Make sure to interact with the page before that. e.g. open up navigation bars, click on buttons, etc.
-
Add JavaScript to an HTML document using your favorite editor, log
Hello World!to the console and verify (using your Developer Tools). -
Declare a constant and a variable in JavaScript, named
PIandfirstName, put the values3.14and"Alice"in them, then log them separately to the console and verify.Solution
const PI = 3.14 let firstName = "Alice" console.log(PI) console.log(firstName) -
Using the constant and variable in the previous step, create a new constant named
messagewith the valueThe value of PI is 3.14 and my first name is Alice. Use template strings to inject the value ofPIandfirstName. Log the message to the console and verify.Solution
const PI = 3.14 let firstName = "Alice" const message = `The value of PI is ${PI} and my first name is ${firstName}` console.log(message) -
Declare a function (using Function Declaration, Function Expression, and Arrow Function) named
addthat takes 2 parametersaandband returns the addition. Verify the function by calling it and logging the result to the console.Solution
Function Declaration:
function add(a, b) { return a + b } console.log(add(5, 6))Function Expression:
const add = function(a, b) { return a + b } console.log(add(5, 6))Arrow Function:
const add = (a, b) => { return a + b } console.log(add(5, 6)) -
Create an array named
fruitsthat contains the following elements:"apple","banana", and"cherry". Log the second item to the console and verify.Solution
const fruits = ["apple", "banana", "cherry"] console.log("second item is:", fruits[1]) -
Create an object named
meusing your own information with these keys:name,age,major,number_of_courses_left, andfavorite_course. Log the values of each key to the console and verify. Use both the Dot Notationobject.keyand Bracket Notationobject["key"].Solution
const me = { name: "Masoud", age: 101, major: "Software Engineering", number_of_courses_left: 0, // thank god favorite_course: "comp3512" } // using both dot and bracket notation console.log(me.name, me["name"]) console.log(me.age, me["age"]) console.log(me.major, me["major"]) console.log(me.number_of_courses_left, me["number_of_courses_left"]) console.log(me.favorite_course, me["favorite_course"]) -
Read about what JSON is.