forked from remarcmij/JavaScript1_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
155 lines (126 loc) · 3.18 KB
/
functions.js
File metadata and controls
155 lines (126 loc) · 3.18 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
// first assignment
function random(x, y, z) {
return x + y + z;
}
console.log(random(1, 2, 3));
// end first assignment
// second assignment
function colorCar(color) {
console.log("a " + color + " car");
}
colorCar("red");
// end second assignment
// third assignment
const arr = ["Dog", "Cat", "Hamster"];
function third(arr) {
console.log(arr);
}
third(arr);
// end third assignment
//fourth assignment
function vehicleType(color, code) {
if (code === 1) {
code = "car";
} else {
code = "motorbike"
}
console.log("a " + color, code);
}
vehicleType("blue", 2)
// end fourth assignment
// fifth assignment
let confirm = 3 === 3 ? console.log("true") : console.log("false");
// end fifth assignment
// sixth assignment
function vehicle(color, age, code) {
if (age === 0) {
age = "okay";
} else if (age === 1) {
age = "used";
} else {
age = "new";
};
switch (code) {
case 1:
code = listOfVehicles[1]
break;
case 2:
code = "race car";
break;
case 3:
code = "tractor";
break;
case 4:
code = "boat";
break;
case 5:
code = "car";
break;
}
console.log("a " + color, age, code);
}
vehicle("blue", 1, 5);
// end sixth assignment
// seventh assignment
const listOfVehicles = ["motorbike", "caravan", "bike", "car", "boat"];
// end seventh assignment
// eighth assignment
console.log(listOfVehicles[3]);
// end eighth assignment
// ninth assignment
vehicle("green", 3, 1);
// end ninth assignment
// tenth assignment
for (i = 0; 1 > i; i++) {
let slogan = "Amazing Joe's Garage, we service " + listOfVehicles;
slogan = slogan.replace(/,/g, ", ");
console.log(slogan);
};
// end tenth assignment
// eleventh assignment
listOfVehicles.push("Jet");
console.log(listOfVehicles);
// end eleventh assignment
// twelfth assignment
let emptyObject = [];
// end twelfth assignment
// thirteenth assignment
const listOfTeachers = ["Dine", "Unmesh", "Jim"];
console.log(listOfTeachers);
// end thirteenth assignment
// fourteenth assignment
listOfTeachers.splice(0, 1, "Dine taught HTML&CSS");
listOfTeachers.splice(1, 1, "Unmesh taught Git");
listOfTeachers.splice(2, 1, "Jim Teaches JavaScript");
console.log(listOfTeachers);
// end fourteenth assignment
// fifteenth assignment
let x = [1, 2, 3];
let y = [1, 2, 3];
let z = y;
console.log(x == y);
console.log(x === y);
console.log(z == y);
console.log(z == x);
// end fifteenth assignment
// sixteenth assignment
let o1 = { foo: 'bar' };
let o2 = { foo: 'bar' };
let o3 = o2;
console.log(o1);
console.log(o2);
console.log(o3);
o2 = { foo: "Kenan" };
console.log(o3);
console.log("It didn't change the value of o3");
o1 = { foo: "HYF" };
console.log(o3);
console.log("It also didn't change the value of o3");
o2 = o3;
console.log(o3);
console.log("No it does not");
// end sixteenth assignment
// seventeenth assignment
let bar = 42;
console.log(typeof typeof bar);
console.log("It has returned a string because the first typeOf property returned the word 'number' and the second typeOf was assigned to the word 'number'")