Basic 5 Logical operators Flashcards
Do a comparison if statement 0 - 13 young and 14 - 28 old, else too old
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`); }
Do an OR expression, if it’s 15 or less has free food, if it’s older than 16 has to pay
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
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.
console.log(id === 100 ? ‘CORRECT’ : ‘INCORRECT’);
Do a switch concept and tell what the switch looks like to another concept..
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.
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.
switch(new Date().getDay()){
}
What is the console.log to represent the switch when looking for dates
console.log(Today is ${day}
)