-
Type the two boolean values --
trueandfalse-- 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
oldEnoughToDrinkthat takes anageas an argument and returnstrueif 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
.lengthto 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
passwordLongEnoughthat accepts a "password" as a parameter and returnstrueif that password is long enough -- you get to decide what constitutes long enough.
-
Write a function
bouncerthat 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
maxthat takes two numbers as arguments, and returns the larger one. -
Write a function
minthat takes two numbers as arguments, and returns the smaller one. -
Write functions
largerandsmallerthat 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: returnstrueif its argument is even, andfalseotherwise.odd: the opposite of the above.positive: returnstrueif its argument is positive, andfalseotherwise.negative: the opposite of the above.
-
A couple of other useful built-in mathematical functions are
Math.random,Math.floorandMath.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 from0ton. -
guessMyNumber: Should accept a single numeric argument and compare it to a random number between0and5. 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.
-