1+
2+
3+ // 1) Create a function that takes 3 arguments and returns the sum of the these arguments
4+
5+ function hallelujah ( a , b , c ) {
6+ return a + b + c
7+ } ;
8+
9+ console . log ( hallelujah ( 14 , 24 , 71 ) ) ;
10+
11+ // 2) Create a function named colorCar that receives a color, and prints out, 'a red car' for example.
12+
13+ function colorCar ( color ) {
14+ return 'a ' + color + ' car'
15+ }
16+
17+ console . log ( colorCar ( 'red' ) ) ;
18+
19+ // 3) Create an object and a function that takes the object as a parameter
20+ // and prints out all of its properties and values.
21+
22+ let myCar = {
23+ year : '2006' ,
24+ color : 'Black' ,
25+ make : 'Toyota' ,
26+ model : 'Prius' ,
27+ motto : 'is the best car of the world :)' ,
28+ } ;
29+
30+ function myCarSpecs ( myCar ) {
31+ console . log ( myCar ) ;
32+ }
33+ myCarSpecs ( myCar ) ;
34+
35+ // 4) Create a function named vehicleType that receives a color, and a code, 1 for car, 2 for motorbike.
36+ // And prints 'a blue motorbike' for example when called as vehicleType("blue", 2)
37+
38+ // I actually need to study this more. I got help on this but not entirely sure about the way I did it.
39+ // Can you please let me know if there is any alternative way of doing this?
40+
41+ const vehicleCategory = {
42+ 1 : 'car' ,
43+ 2 : 'motorbike' ,
44+ } ;
45+ function vehicleType ( color , type ) {
46+ console . log ( "a " + color + " " + vehicleCategory [ type ] ) ;
47+ }
48+
49+ vehicleType ( "blue" , 2 ) ;
50+
51+ // 5) Can you write the following without the if statement, but with just as a single line with console.log(...);?
52+
53+ // if (3 === 3) {
54+ // console.log("yes");
55+ // } else {
56+ // console.log("no");
57+ // }
58+
59+ console . log ( 3 === 3 ? "yes" : "no" ) ;
60+
61+ // 6) Create a function called vehicle, like before,
62+ // but takes another parameter called age, so that vehicle("blue", 1, 5) prints 'a blue used car'
63+
64+ const vehicleCategory2 = {
65+ 1 : ' used ' ,
66+ 2 : 'motorbike' ,
67+ 3 : 'yatch' ,
68+ 4 : 'speedboat' ,
69+ 5 : 'car'
70+ } ;
71+ function vehicle ( color , age , type ) {
72+ console . log ( "a " + color + vehicleCategory2 [ 1 ] + vehicleCategory2 [ 5 ] ) ;
73+ }
74+
75+ vehicle ( "blue" , 1 , 5 ) ;
76+
77+ // haha please write the proper way of doing this. I feel like I manipulated the system :)
78+
79+
80+ // 7) Make a list of vehicles, you can add "motorbike", "caravan", "bike", or more.
81+
82+ let myListOfVehicles = [ "motorbike" , "caravan" , "bike" , "car" , "yatch" , "jet-ski" ]
83+
84+ console . log ( myListOfVehicles ) ;
85+
86+
87+ // 8) How do you get the third element from that list?
88+
89+ console . log ( myListOfVehicles [ 2 ] ) ;
90+
91+ // 9) Change the function vehicle to use the list of question 7. So that vehicle("green", 3, 1)
92+ //prints "a green new bike".
93+
94+ function newVehicle ( color , category , age ) {
95+ if ( age <= 4 ) {
96+ age = "new" ;
97+ } else {
98+ age = "used" ;
99+ }
100+ console . log ( "a " + color + " " + age + " " + myListOfVehicles [ 3 ] ) ;
101+ }
102+
103+ newVehicle ( "green" , 3 , 1 ) ;
104+
105+
106+ // 10) Use the list of vehicles to write an advertisement. So that it prints something like:
107+ //"Amazing Joe's Garage, we service cars, motorbikes, caravans and bikes.". (Hint: use a for loop.)
108+
109+ // I HAVE NO ANSWER FOR THIS QUESTION.
110+
111+ // // Hint, the output should be correct English with all the punctuation in place
112+ // (that's the challenge). So plurals for the vehicle types, commas followed by a single space,
113+ // the word and to replace the final comma and closed off by a period.
114+
115+ // 11) What if you add one more vehicle to the list, can you have that added to the
116+ // advertisement without changing the code for question 10?
117+
118+ // I HAVE NO ANSWER FOR THIS QUESTION.
119+
120+ // 12) Create an empty object.
121+
122+ let emptyObject = { } ;
123+
124+ console . log ( emptyObject ) ;
125+
126+ // 13) Create an object that contains the teachers that you have had so far for the different modules.
127+
128+ emptyObject . teachers = 'Philipp & Rob, Unmesh & Bonan, Yash' ;
129+
130+ console . log ( emptyObject . teachers ) ;
131+
132+ // 14) Add a property to the object you just created that contains the languages that they have taught you.
133+
134+ emptyObject . classes = 'HTML & CSS, Git, Javascript'
135+
136+ console . log ( emptyObject ) ;
137+
138+
139+ // 15) Write some code to test two arrays for equality using == and ===. Test the following:
140+
141+ let x = [ 1 , 2 , 3 ] ;
142+ let y = [ 1 , 2 , 3 ] ;
143+ let z = y ;
144+ // What do you think will happen with x == y, x === y and z == y and z == x? Prove it!
145+
146+ console . log ( x == y ) ; // false, different memory locations?
147+ console . log ( x === y ) ; // false, different memory locations?
148+ console . log ( z == y ) ; // true, same type
149+ console . log ( z == x ) ; // false, different types ?
150+
151+ // The == equality operator converts the operands if they are not of the same type,
152+ //then applies strict comparison. If both operands are objects,
153+ //then JavaScript compares internal references which are equal
154+ //when operands refer to the same object in memory.
155+
156+ // The identity operator returns true if the operands are strictly equal (see above) with no type conversion.
157+
158+
159+ // Don't cheat! Seriously - try it first.
160+
161+ // Check out this Fiddle. You need to open your browser’s Developer Tools to see the console output.
162+
163+ //Press the Run button in the upper right corner to run the code.
164+
165+ // More insights from this Stack Overflow question.
166+
167+ // 16) Take a look at the following code:
168+
169+ // let o1 = { foo: "bar" };
170+ // let o2 = { foo: "bar" };
171+ // let o3 = o2;
172+ // Show that changing o2 changes o3 (or not) and changing o1 changes o3(or not).
173+
174+ // Does the order that you assign (o3 = o2 or o2 = o3) matter?
175+
176+ // 17) What does the following code return? (And why?)
177+
178+ // let bar = 42;
179+ // typeof typeof bar;
180+ // ‘Coerce' means to try to change - so coercing var x = '6' to number means
181+ // trying to change the type to number temporarily.
0 commit comments