-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise1.html
More file actions
67 lines (56 loc) · 2.17 KB
/
exercise1.html
File metadata and controls
67 lines (56 loc) · 2.17 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab3 -- Exercise 1</title>
</head>
<body>
<h1>JavaScript Lab Exercise 1</h1>
<script>
// exercise 1A
try {
var name1 = "John";
let name2 = "Jane";
const name3 = "Alice";
name2 = "Joe";
name3 = "Bob";
} catch (error) {
console.error("Error: cannot reassign const");
}
// exercise 1B
let string1 = "Hello, World!"
let string2 = "JavaScript is fun!"
console.log(string1.length);
console.log(string1, string2);
let string3 = "JavaScript is awesome!";
console.log(string3);
// exercise 1C
let name = "Alice";
let age = 25;
console.log(`My name is ${name} and I am ${age} years old`);
// exercise 1D
const students = ["Alice", "Tom", "Charlie"];
const ages = [19, 21, 20];
for (let i = 0; i < students.length; i++) {
console.log(`My name is ${students[i]} and I am ${ages[i]} years old`);
}
// exercise 1E
let date = new Date();
console.log("en-CA:", date.toLocaleDateString("en-CA"));
console.log("en-US:", date.toLocaleDateString("en-US"));
console.log("Year:", date.getFullYear());
console.log("Month:", date.getMonth());
console.log("Day of the week:", date.toLocaleDateString("en-US", {weekday: "long"}));
if (date.getMonth() === 11 || date.getMonth() <= 1) {
console.log("It's winter!");
} else if (date.getMonth() >= 2 && date.getMonth() <= 4) {
console.log("It's spring!");
} else if (date.getMonth() >= 5 && date.getMonth() <= 7) {
console.log("It's summer!");
} else {
console.log("It's fall!");
}
</script>
</body>
</html>