Note: Before getting started on these exercises, please be certain that you've read through the root README.md file in this repository.
-
Type the two boolean values --
true
andfalse
-- into your console. -
Use the console to accomplish the following:
- Write an expression using
>
that will evaluate tofalse
- Write an expression using
>
that will evaluate totrue
- Write an expression using
<
that will evaluate tofalse
- Write an expression using
<
that will evaluate totrue
- Write an expression using two numbers and
===
that will evaluate totrue
- Write an expression using two numbers and
===
that will evaluate tofalse
- Write an expression using two strings and
===
that will evaluate totrue
- Write an expression using two strings and
===
that will evaluate tofalse
- Write an expression using
-
Fill in the
???
with the following operators or values to make the statements output the expected Boolean value.12 ??? 78 // => true 24 ??? 16 // => false 45 !== ??? // => true "45" ??? 45 // => false "6" ??? "six" // => true
-
Write a function
oldEnoughToDrink
that takes anage
as an argument and returnstrue
if the person with that age is old enough to drink. -
There's an easy way to figure out how long a string is by adding
.length
to the end of it. Try this out in the console:
"hello".length;
"".length;
"John Doe".length;
Write a function sameLength
that accepts two strings as arguments, and
returns true
if those strings have the same length, and false
otherwise.
- Write a function
passwordLongEnough
that accepts a "password" as a parameter and returnstrue
if that password is long enough -- you get to decide what constitutes long enough.
-
Write a function
bouncer
that accepts a person's name and age as arguments, and returns either "Go home, NAME.", or "Welcome, NAME!" (where NAME is the parameter that represents the person's name) depending on whether or not the person is old enough to drink. -
Write a function
max
that takes two numbers as arguments, and returns the larger one. -
Write a function
min
that takes two numbers as arguments, and returns the smaller one. -
Write functions
larger
andsmaller
that each accept two strings as arguments, and return the larger and smaller strings, respectively.
-
Fill in the
???
with the following operators or values to make the statements output the expected Boolean value.106 ??? 12 // => false "wiz" ??? "wiz" // => true 7 * 7 ??? 49 // => true 12 ??? (24 / 2) // => false (20 % 2) <= ??? // => true (9 / 3) + (5 * 5) === ??? // => true
-
Write the following functions that each accept a single number as an argument:
even
: returnstrue
if its argument is even, andfalse
otherwise.odd
: the opposite of the above.positive
: returnstrue
if its argument is positive, andfalse
otherwise.negative
: the opposite of the above.
-
A couple of other useful built-in mathematical functions are
Math.random
,Math.floor
andMath.ceil
. Look these functions up on MDN to learn how they work, and use them to implement the following functions:-
randInt
: Should accept a single numeric argument (n
), and return a number from0
ton
. -
guessMyNumber
: Should accept a single numeric argument and compare it to a random number between0
and5
. It should return one of the following strings:- "You guessed my number!" if the argument matches the random number.
- "Nope! That wasn't it!" if the argument did not match the random number.
-