Variables Flashcards
Use variables to store all three data types and then log them to the console.
var myName = 'Scott'; console.log(myName); var myAge(18); console.log(myAge) var amVirgin: true; console.log(amVirgin)
The weather forecast can change everyday, how could you save time editing the temperature with the use of a variable?
var temp = 'Monday: Raining cats and dogs' temp = 'Tuesday: Sunny'; console.log(temp);
What is the difference between using an equal sign to assign a value to an variable and when we want the computer to compare a value in an if/else statement?
= used to assign values to a variable
=== used to compare values (Ex. if/else statement)
How can you write an if/else statement if we have a question that has multiple yes conditions, or multiple no conditions (Give Example)?
if (stopLight === 'red') { console.log('Don't go!'); } else if (stopLight === 'yellow') { console.log('Get ready!'); } else if (stopLight === 'green') { console.log('Go!'); } else { console.log('Caution, unknown!'); }
What are the logical operators for the following:
- Both must be true
- Either ca be true
- I want to make sure this is the opposite of what it really is
- There should not be equal to each other
- &&
- | |
- !
- !==
Using else if is a great tool for when we have a few different conditions we’d like to consider. However, else if is limited. What would be a better way to write a JavaScript cash register, without using an if, else if, else statement?
switch (groceryItem) { case: 'orange': console.log('An orange costs $1.90'); break; case: 'apple': console.log('An apple costs $2.00'); break; case: 'lemon' console.log('A lemon costs $3.00'); break; default: console.log('Unknown item!'); }