-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_Variables.js
More file actions
160 lines (107 loc) · 4.96 KB
/
1_Variables.js
File metadata and controls
160 lines (107 loc) · 4.96 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Week 1 - Variables.
// In the following exercises, you will need to place your code or answer underneath each
// exercise prompt.
// First try answering these without using references or looking up any information.
// Then, check your answer by using references and/or running your code.
// You can run your JS code using the Chrome or Firefox Developer tools, or by using Node.js.
// Feel free to update your answers if you got them wrong at first -- this exercise is for your own learning.
// But make sure you understand why the correct answer is right.
// Data Types and Variables
// Exercise 1. Simply declare a variable named 'emptyVariable'
let emptyVariable;
// Exercise 2. Declare a variable called 'myName'
let myName;
// Exercise 3. Assign your name as the value for 'myName'
myName = "Gisselle"; //assigned variable
//Adding a space so it is easier to see different answers.
// Exercise 4. Declare a variable called dreamDestination and give it the value
// of what your dream vacation destination is.
const dreamDestination = "Greece";
// Exercise 5. Make the following variables and assignments
// - a variable called num1 with a value greater than 1 and less than 10
//assuming we have to pick the number ourselves
let num1 = 4;
// - a variable called num2 with a value of greater than or equal to 1 and less
// than or equal to 10
let num2 = 10;
// Exercise 6. Write a comment below explaining the difference between the rules
// for num1 and num2 from Exercise 5. What numbers would be valid values for
// num2 but not num1?
/*my answer: num1 is exclusive and does not include 1 or 10, but num2 is inclusive and includes 1 and 10 in the range of numbers.*/
// Exercise 7. Now we will try some addition.
// a. Assign the the values of 4 and 6 to num1 and num2, respectively.
num1 = 4;
num2 = 6;
// b. Make a new variable called 'theSum', and use 'num1' and
// 'num2' to assign its value using the "+" operator.
const theSum = num1 + num2;
console.log(theSum);
//Exercise 8. Now we will try some multiplication.
//Make a new variable called 'theProduct', multiply num1 and num2 and assign
//the resulting value to 'theProduct'.
const theProduct = num1 * num2;
console.log(theProduct);
// Exercise 9.
// Make a new variable called 'statement' and using 'myName' and
// 'dreamDestination' and the concatenation method of your choice, make the
// value of statement to be:
// "Hi, my name is <your name>, and I can't wait to visit <your destination>!"
const statement = "Hi, my name is " + myName + ", " + "and I can't wait to visit " + dreamDestination + "!";
console.log(statement);
// *NOTE* For the following exercises, put your answers in the line below
// the description of each exercise. For example, below a prompt, you may see:
// let myAnswerForExercise10= "";
// If your answer is "foo", then fill in the line to be:
// let myAnswerForExercise10 = "foo";
// Exercise 10. What is the data type of the value stored in 'dreamDestination',
// place your answer in the quotes below:
const myAnswerForExercise10 = "string";
// Exercise 11. What is the data type of the value stored in 'product',
// place your answer in the quotes below:
const myAnswerForExercise11 = "number";
// Exercise 12. What do you think the value of emptyVariable is?
// Place your answer below:
// const myAnswerForExercise12 = "undefined";
// Exercise 13. If
const A = "R";
const B = 1;
const C = 4;
const D = "D";
// // What is the value of B + C
// const myAnswerForExercise13 = 5;
// console.log(B+C);
// Exercise 14 What is the value of
// A + "n" + D
const myAnswerForExercise14 = "RnD"; //Important to pay attention to var values for these questions. I tried them on my own then checked with console.log
console.log(A + "n" + D);
// Exercise 15 What is the value of
// A + B * 2 + D + C / 2:
const myAnswerForExercise15 = "R2D2";
console.log(A + B * 2 + D + C / 2);
// Exercise 16 What is the value of A * B
const myAnswerForExercise16 = NaN;
console.log(A*B);
// Exercise 17 What is the value of true || false
const myAnswerForExercise17 = true;
console.log(true || false);
// Exercise 18 What is the value of 1 === "1"
const myAnswerForExercise18 = false;
console.log(1==="1");
// Exercise 19 What is the value of 1 == "1"
const myAnswerForExercise19 = true;
console.log(1 == "1");
// Exercise 20 What is the value of 1 < 1
const myAnswerForExercise20 = false;
console.log(1<1);
// Exercise 21 What is the value of 1 < 2 < 3
const myAnswerForExercise21 = true;
console.log(1 < 2 < 3);
// Exercise 22 What is the value of 2 < 1 < 3
const myAnswerForExercise22 = true;
console.log(2 < 1 < 3);
// Congrats, you made it to the end!
// Did you find this easy or hard? If you used references, which ones helped you?
// Please answer in a comment below.
//I found it easy, but I did need a refresher on whether to use let or const at the start. I now know that const cannot be reinitialized, while let can. Both cannot be redeclared.
// Email your file to the course staff,
// or commit your file to GitHub and email us a link.