Basic 5 Logical operators Flashcards

1
Q

Do a comparison if statement 0 - 13 young and 14 - 28 old, else too old

A
const dude = 'john'
const old = 29;
if(old > 23 && old < 30){
  console.log(`${old} Is a john`);
} else if(old >= 30 && old <= 40){
  console.log(`${old} is test 2`)
} else {
  console.log(`${old} Is and adult`);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Do an OR expression, if it’s 15 or less has free food, if it’s older than 16 has to pay

A

if(old < 14 || old > 65){
console.log(${old} Cannot race)
} else {
console.log(${old} Has been registered);
} //if don’t remember look for REFERENCE in viscod with ctrl + f

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

What is the ternary operator explain what are the symbols

The ternary operator is an operator that takes three arguments. The first argument is a comparison argument, the second is the result upon a true comparison, and the third is the result upon a false comparison. If it helps you can think of the operator as shortened way of writing an if-else statement. It is often used as a way to assign variables based on the result of an comparison. When used correctly it can help increase the readability and reduce the amount of lines in your code.

A

console.log(id === 100 ? ‘CORRECT’ : ‘INCORRECT’);

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

Do a switch concept and tell what the switch looks like to another concept..

A

const color = ‘red’;

switch(color){
case 'red':
  console.log('Color is red');
  break;
case 'blue':
  console.log('Color is blue');
  break;
default:
  console.log('Color is not red or blue');
  break;
}

be mindful about the : after the case is called since this will start the being of the case.

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

what is the formula to get the date with switch?

note: Keep in mind that between the brackets, you should put what you are going to evaluate in this is the date.

A

switch(new Date().getDay()){

}

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

What is the console.log to represent the switch when looking for dates

A

console.log(Today is ${day})

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