Module 1 - Conditionals 1 Flashcards
Write a function called “isOldEnoughToDrink”. Given a number, in this case an age, “isOldEnoughToDrink” returns whether a person of this given age is old enough to legally drink in the United States. The legal drinking age in the United States is 21.
function isOldEnoughToDrink(age) {
if (age >= 21) {
return true;
} else if (age <= 21) {
return false;
}
Write a function called “isOldEnoughToDrive”. Given a number, in this case an age, “isOldEnoughToDrive” returns whether a person of this given age is old enough to legally drive in the United States. Notes: Legal driving age 16.
function isOldEnoughToDrive(age) {
if (age >= 16) {
return true;
} else if (age <= 16) {
return false;
}
}
Write a function called “isOldEnoughToVote”. Given a number, in this case an age, ‘isOldEnoughToVote’ returns whether a person of this given age is old enough to legally vote in the United States. Notes: Legal age 18
function isOldEnoughToVote(age) {
if (age >= 18) {
return true;
} else if (age <=18) {
return false;
}
}
Write a function called “isOldEnoughToDrinkAndDrive”. Given a number, in this case an age, “isOldEnoughToDrinkAndDrive” returns whether a person of this given age is old enough to legally drink and drive in the United States. Notes:
The legal drinking age in the United States is 21.
It is always illegal to drink and drive in the United States.
function isOldEnoughToDrinkAndDrive(age) {
if (age >= 21) {
return false;
} else if (age <=21) {
return false;
}
}
Write a function called “checkAge”. Given a person’s name and age, “checkAge” returns one of two messages: “Go home, {insert_name_here}!”, if they are younger than 21. “Welcome, {insert_name_here}!”, if they are 21 or older. Naturally, replace “{insert_name_here}” with the given name. :)
function checkAge(name, age) {
if (age < 21) {
return “Go home, “ + name + “!”;
} else if (age >= 21);
return “Welcome, “ + name + “!”;
}
Write a function called “isGreaterThan10”. Given a number, “isGreaterThan10” returns whether the given number is greater than 10.
if (num > 10) {
return true;
} else {
return false;
}
}
Write a function called “isLessThan30”. Given a number, “isLessThan30” returns whether the given number is less than 30.
if (num < 30) {
return true;
} else {
return false;
}
}
Write a function called “equalsTen”. Given a number, “equalsTen” returns whether or not the given number is 10.
function equalsTen(num) {
if (num === 10) {
return true;
} else if (num != 10);
return false;
}