forked from turingschool/m0_fe_conditionals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparisons.js
130 lines (100 loc) · 4.88 KB
/
comparisons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// In the exercises below, write your own code where indicated
// to achieve the desired result.
// One example is already completed. Your task is to complete
// any remaining prompt.
// Make sure to run the file in your command line using `node <filename>.js`
// -------------------
// PART 1: Comparing variables
// -------------------
var numberTeachers = 4
var numberStudents = 20
var stringTeachers = "4"
var numberDogs = 0
// EXAMPLE: log the result of the comparison: is numberTeachers greater than numberStudents?
console.log("Is numberTeachers greater than numberStudents?", numberTeachers > numberStudents);
// this should log: "Is numberTeachers greater than numberStudents?" false
// YOU DO: log the result of the comparison: is numberTeachers less than numberStudents?
console.log("Is numberTeachers less than numberStudents?", numberTeachers < numberStudents);
// this should log: true
// YOU DO: log the result of the comparison: is numberTeachers strictly equal to stringTeachers?
console.log("Is numberTeachers strictly equal to stringTeachers?", numberTeachers === stringTeachers);
// this should log: false
// YOU DO: log the result of the comparison: is numberTeachers not equal to numberStudents?
console.log("Is numberTeachers not equal to numberStudents?", numberTeachers !== numberStudents);
// this should log: true
// YOU DO: log the result of the comparison: is numberStudents greater than or equal to 20?
console.log("Is numberStudents greater than or equal to 20?", numberStudents >= 20);
// this should log: true
// YOU DO: log the result of the comparison: is numberStudents greater than or equal to 21?
console.log("Is numberStudents greater than or equal to 21?", numberStudents >= 21);
// this should log: false
// YOU DO: log the result of the comparison: is numberStudents less than or equal to 20?
console.log("Is numberStudents less than or equal to 20?", numberStudents <= 20);
// this should log: true
// YOU DO: log the result of the comparison: is numberStudents less than or equal to 21?
console.log("Is numberStudents less than or equal to 21?", numberStudents <= 21);
// this should log: true
// #-------------------
// PART 2: Articulating what you are doing
// #-------------------
// For the following prompts, you will be given a line of code and your task is to type out a Comment,
// in English, explaining what that line of code is doing, including what the comparison will evaluate to.
// Be as technically precise as possible, but don't just copy and paste a definition from the readings.
// Make sure YOU can explain it that way!
console.log(4 < 9);
// YOU DO: Explain.
// The console.log is evaluating the question of is 4 less than 9.
// In this case 4 *is less than 9 so it evaluates to true.
var books = 3;
console.log(4 < books);
// YOU DO: Explain.
// The console log is evaluating the question of is 4 less than assignment operator 'books', which has a value of 3.
// In this case 4 is *not less than 3, so it evaluates to false.
var friends = 6;
var siblings = 2;
console.log(friends > siblings);
// YOU DO: Explain.
// The console log is evaluating whether assignment operator 'friends' is greater than assignment operator 'siblings'.
// 'friends' has a value of 6, and 'siblings has a value of 2.
// In this case 6 *is less than 2, so it evaluates to true.
var attendees = 9;
var meals = 8;
console.log(attendees !== meals);
// YOU DO: Explain.
// The console log is evaluating whether assignment operator 'attendees' is not equal to assignment operator 'meals'.
// 'attendees' has a value of 9, and meals has a value of 8.
// Therefore because 9 and 8 are *not equal, it evaluates to true.
// #-------------------
// PART 3: Logical Operators
// #-------------------
var isHungry = true;
var finishedHomework = false;
// EXAMPLE:
// Determine if the user is hungry and has completed their homework
console.log(isHungry && finishedHomework);
// Determine if the user is hungry or has completed their homework
console.log(isHungry || finishedHomework);
var lovesToPlay = true;
var lovesDogPark = false;
var lovesTreats = true;
var age = 1;
// YOU DO:
// Determine if the dog loves to play and loves treats
console.log(lovesToPlay && lovesTreats);
// True
// Determine if the dog loves to play and loves the dog park
console.log(lovesToPlay && lovesDogPark);
// False
// Determine if the dog loves to play or loves the dog park
console.log(lovesToPlay || lovesDogPark);
//True
// Determine if the dog loves to play and is a puppy
console.log(lovesToPlay && age);
// What did your final line of code evaluate to?
// Why do you think that is? Explain.
// ANSWER:
// The answer evaluated to 1. Booleans are evaluated based on True / False propositions
// Numbers are evaluated based on comparison operators.
// If we assume that a puppy becomes a junior dog by age 1 then...
console.log(lovesToPlay && age < 1);
// Then the question of whether this dog loves to play and is a puppy? It evaluates to false.