Module 1 - Conditionals 1 Flashcards

1
Q

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.

A

function isOldEnoughToDrink(age) {

if (age >= 21) {

return true;

} else if (age <= 21) {

return false;

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

function isOldEnoughToDrive(age) {
if (age >= 16) {
return true;
} else if (age <= 16) {
return false;
}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

function isOldEnoughToVote(age) {

if (age >= 18) {

return true;

} else if (age <=18) {

return false;

}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

function isOldEnoughToDrinkAndDrive(age) {

if (age >= 21) {

return false;

} else if (age <=21) {

return false;

}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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. :)

A

function checkAge(name, age) {
if (age < 21) {
return “Go home, “ + name + “!”;
} else if (age >= 21);
return “Welcome, “ + name + “!”;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a function called “isGreaterThan10”. Given a number, “isGreaterThan10” returns whether the given number is greater than 10.

A

if (num > 10) {
return true;
} else {
return false;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a function called “isLessThan30”. Given a number, “isLessThan30” returns whether the given number is less than 30.

A

if (num < 30) {
return true;
} else {
return false;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a function called “equalsTen”. Given a number, “equalsTen” returns whether or not the given number is 10.

A

function equalsTen(num) {
if (num === 10) {
return true;
} else if (num != 10);
return false;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly