Variables Flashcards

1
Q

Use variables to store all three data types and then log them to the console.

A
var myName = 'Scott';
console.log(myName);
var myAge(18);
console.log(myAge)
var amVirgin: true;
console.log(amVirgin)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The weather forecast can change everyday, how could you save time editing the temperature with the use of a variable?

A
var temp = 'Monday: Raining cats and dogs'
temp = 'Tuesday: Sunny';
console.log(temp);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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?

A

= used to assign values to a variable

=== used to compare values (Ex. if/else statement)

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

How can you write an if/else statement if we have a question that has multiple yes conditions, or multiple no conditions (Give Example)?

A
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!');
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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
A
  1. &&
  2. | |
  3. !
  4. !==
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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?

A
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!');
 }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly