-
Notifications
You must be signed in to change notification settings - Fork 0
/
pract.html
281 lines (234 loc) · 6.77 KB
/
pract.html
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//-------------------Q1-------------------:
/*
The following statements are representing variables declarations.
Each statement has an error you need to fix it.
Please run the code listed down in a console.
Add the right declarations in the [write your code here] section.
Note: in order to see the errors in the console, please:
1.uncomment the statements one by one.
2.run your liver-server on index.html page.
*/
let test = null;
let name = "Josh";
let firstproject = "Hello World";
let test1= 1;
let y = 5;
let sum = 40;
let x = "foo";
let remainder =( 10 % 2 ==0);
/*
Write your code here
*/
//-------------------Q2.1-------------------:
//Declare a variable called boolean and assign it a value of true.
/*
Write your code here
*/
let boolean = true
//-------------------Q2.2-------------------:
// Change the value of the Boolean variable in the previous question to be false.
/*
Write your code here
*/
boolean = false
//-------------------Q3-------------------:
/*
print your Full Name
1. Declare 3 variables called
-firstName
-lastName
-fullName
2. assign your personal information as values, and print your full name on console
Note:
- The result should have the format of: : "Hello, I am (your full name)"
*/
/*
Write your code here
*/
let firstname = "lucy"
let lastname = "ongondo"
fullname = firstname + " "+ lastname
console.log("hello, I am ", (fullname));
//-------------------Q4-------------------:
/*
One Awesome Message
1. Create the following variables:
- firstName1
- interest
- hobby
2. Create a variable named awesomeMessage and set it to an awesome message using
string concatenation and the variables above.
3. Log the awesomeMessage variable to the console.
Notes:
- The `awesomeMessage` should have the format of:
Hi, my name is __. I love __. In my spare time, I like to ___.
*/
/*
Write your code here
*/
let firstName1 = "Lucy"
let interest = "Cooking"
let hobby = "watching"
let awesomeMessage = ' Hi, my name is'+' '+ firstName1 +'. I love ' + interest +'. In my spare time, I like to'+ hobby +' .'
console.log(awesomeMessage )
//-------------------Q5-------------------:
/*
Calculate your age in 2030
Want to find out how old you'll be? Calculate it!
1. Store your birth year in a variable.
2. Store a future year (2030) in a variable.
3. Calculate your age for that year based on the stored values.
For example, if you were born in 1990, then in 2030 you'll be 40 .
Notes:
- The result should have the format of:
"I will be NN in YYYY".
*/
/*
Write your code here
*/
let birthyear = 1998;
let futureyear = 2030;
let age= futureyear - birthyear;
console.log( "i will be",(age), "in", (futureyear))
//-------------------Q6-------------------:
/*
1. Uncomment the expressions below the these instructions.
2. Find out the results of the following expressions.
3. Double check your answer on console.
4. Replace null or ??? with your answer.
*/
let result = 15 - 6 * 2 + 8 / 4;
console.log( result)
result = 5;
let convert = 2 + "1";
console.log( convert)
convert = 21;
let sum1 = 5 + 4 + "2";
console.log( sum)
sum1 = 40;
let quotient = 20 / 4;
console.log( quotient)
quotient = 5;
let remainder1 = 8 % 3;
console.log( remainder1)
remainder1 = 2;
let exponent = 2 ** 8;
console.log( exponent)
exponent = 256;
let n = 2;
n += 5; // n = 7
console.log( n)
n *= 2; // n = 14
console.log( n)
let r = 3;
const s = r++; // r = 4 , s = 3
console.log( r)
console.log( s)
let a = 3;
const b = ++a; // a = 4 , b = 4
console.log( a)
console.log( b)
let j = 7;
j **= "hello"; // j = NaN
console.log( j)
let signedIn;
console.log(signedIn); //undefined
//-------------------Q7-------------------:
// Fill in the null,and uncomment the expression (4 expressions)
/*Complete the expression by filling in the missing number.
The expression should equal 20.*/
1 + 1 + 2 + 3 + 5 + 8;
/*Complete the expression by filling in the missing number.
The expression should equal true.*/
10 == 10;
/*Complete the expression by filling in the missing operator.
The expression should equal 37.*/
12+(5 * 5)
/*Complete the expression by filling in the missing operator.
The expression should equal 2.*/
3 * 4% 5;
//-------------------Q8-------------------:
/*Write an expression that uses at least 3 different arithmetic operators.
The expression should equal 36.
Hint: +, -, *, /, and % are possible arithmetic operators
*/
6*5+10-4
//-------------------Q9-------------------:
// What does typeof() method return in javaScript?
// Uncomment the expressions below and replace null with your answer
let result1 = typeof 5;
console.log(result1)
// result1 = number;
let result2 = typeof -5;
console.log(result2)
// result2 = numnber;
let result3 = typeof true;
console.log(result3)
// result3 = boolean;
let result4 = typeof "SHA";
console.log(result4)
// result4 = string;
let num;
let result5 = typeof num;
console.log(result5)
// result5 = undefined;
// Note: you can check the resources section in README file.
//-------------------Q10-------------------:
/*
The Temperature Converter:
1. Store a celsius temperature into a variable.
2. Convert it to fahrenheit and output "NN°C is NN°F".
3. Now store a fahrenheit temperature into a variable.
4. Convert it to celsius and output "NN°F is NN°C."
Note : check the resource part in README file to see the
conversion equation.
*/
let degree =50;
let degrefaren =1.8 * degree +32;
console.log( degree + "°C is " + degrefaren + "°F")
let faren = 200;
let farendegre =1.8 / faren +32;
console.log( faren + "°F is " + farendegre + "°C")
//-------------------Q11-------------------:
/*
1. Create a variable called bill and assign it
the result of 10.25 + 3.99 + 7.15 (don't perform the calculation yourself, let JavaScript do it!).
2. Next, create a variable called tip and assign it the result
of multiplying bill by a 16% tip rate.
3. Finally, add the bill and tip together and store it into a variable called total.
4. Print the total to the JavaScript console.
*/
let bill =(10.25+3.99+7.15);
let tip = bill * 0.16
total = bill+tip
console.log(total)
//-------------------Q12-------------------:
// Given that
let float = 4.5;
// Replace null with your answer in the next expressions.
let integer = parseInt(float);
console.log(integer)
integer = 4;
let roundDown = Math.floor(float);
console.log(roundDown)
roundDown = 4;
let roundedUp = Math.ceil(float);
console.log(roundedUp)
roundedUp = 5;
let power = Math.pow(3, 3);
console.log(power)
power = 27;
/-------------------Good Luck--------------------------/
</script>
</body>
</html>