- Open the
index.html
file using a Live Server - Open the DevTools Console
- Perform the following exercises by making changes to
script.js
-
Using
const
, define a variable calledx
with the value5.25
- Log it to the console using
console.log('The value of x is', x)
- Log it to the console using
-
Using
let
, define a variable calledy
with the value'Hello!'
- Log it to the console
-
Using
var
, define a variable calledz
with the valuetrue
- Log it to the console
-
Define a variable called
sum
with the value ofx
plus15
- Log it to the console
-
Define a variable called
bodyClass
with the value ofdocument.body.className
- Log it to the console
-
Change
document.body.className
to"loading"
-
Log the value of
bodyClass
to the console again -
Define a variable called
randomNumber
with the value ofMath.random()
- Log it to the console
-
Define a variable called
mainClass
to store theclassName
of themain
element on the page- Log it to the console
-
Define a function
hello
that displays analert
with the message"Hello, world!"
- Invoke it to verify that it works
-
Update the
hello
function above toconsole.log
a message ("I am the hello function"
) after displaying thealert
. -
Define a function
hi
that takes a single argumentname
and returns the string"Hi, <name>!"
.- when invoked like
hi('John')
it should return"Hi, John!"
- when invoked like
hi('Ben')
it should return"Hi, Ben!"
- when invoked like
-
Log the output of the
hi
function to the console -
Define a function
add
that takes two arguments:num1
andnum2
and returns the sum ofnum1
andnum2
-
Define a function
random5
that does not take any arguments and returns a random number between1
and5
(no decimals)- Hint: Multiply
Math.random()
by 5 and then useMath.round()
- Hint: Multiply