Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a92d297

Browse files
committed
add week3
1 parent ae54b78 commit a92d297

14 files changed

+221
-0
lines changed

Week3/.DS_Store

6 KB
Binary file not shown.

Week3/More-JS-1.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
//1 Create a function that takes 3 arguments and returns the sum of the these arguments.
4+
function sum(a, b, c) {
5+
return a + b + c;
6+
}
7+
let result = sum(1, 2, 3);
8+
console.log(result);

Week3/More-JS-12.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
//12 Create an empty object.
3+
let emptyObj = {};

Week3/More-JS-13-14.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
//13 Create an object that contains the teachers that you have had so far for the different modules.
3+
//14 Add a property to the object you just created that contains the languages that they have taught you.
4+
5+
6+
let teachers = {
7+
Philip : "HTML & CSS",
8+
Hardit : "CLI",
9+
Unmesh : "Git",
10+
Sander : "JS"
11+
}
12+
console.log(teachers);
13+
14+
15+
16+
17+

Week3/More-JS-15.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
//15 Write some code to test two arrays for equality using == and ===. Test the following:
3+
/* let x = [1, 2, 3];
4+
let y = [1, 2, 3];
5+
let z = y;
6+
What do you think will happen with x == y, x === y and z == y and z == x? Prove it!
7+
*/
8+
let x = [1, 2, 3];
9+
let y = [1, 2, 3];
10+
let z = y;
11+
console.log(x==y);
12+
console.log(x===y);
13+
console.log(z==y); // true
14+
console.log(z===x);

Week3/More-JS-16.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
//16
3+
/* Take a look at the following code:
4+
5+
let o1 = { foo: "bar" };
6+
let o2 = { foo: "bar" };
7+
let o3 = o2;
8+
9+
Show that changing o2 changes o3 (or not) and changing o1 changes o3(or not).
10+
Does the order that you assign (o3 = o2 or o2 = o3) matter?
11+
*/
12+
let o1 = { foo: "bar" };
13+
let o2 = { foo: "bar" };
14+
let o3 = o2;
15+
// didn't work so far

Week3/More-JS-17.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
//17 What does the following code return? (And why?)
3+
/*
4+
let bar = 42;
5+
typeof typeof bar;
6+
‘Coerce' means to try to change - so coercing var x = '6' to number means trying to change the type to number temporarily.
7+
*/
8+
let bar = 42;
9+
typeof typeof bar;
10+
console.log(typeof bar); // number
11+
console.log(typeof typeof bar); // type of number is string
12+

Week3/More-JS-2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
//2 Create a function named colorCar that receives a color, and prints out, 'a red car' for example.
3+
function colorCar(color){
4+
return "a " + color + " car";
5+
}
6+
console.log(colorCar("red"));

Week3/More-JS-3.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
/*3 Create an object and a function that takes the object as a parameter and
3+
prints out all of its properties and values.*/
4+
let materials= [
5+
{
6+
week1 : "HTML",
7+
},
8+
{
9+
week2 : "CSS",
10+
},
11+
{
12+
week3 : "git",
13+
}
14+
]
15+
function course(materials){
16+
for(let i=0; i<materials.length;i++){
17+
18+
}
19+
}
20+
let i;
21+
console.log(materials);
22+

Week3/More-JS-4.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
//4 Create a function named vehicleType that receives a color, and a code, 1 for car, 2 for motorbike. And prints 'a blue motorbike' for example when called as vehicleType("blue", 2)
3+
4+
function vehicleType(color,code){
5+
if (code === 1)
6+
console.log("a " + color + " car")
7+
8+
else if
9+
(code===2)
10+
console.log("a " + color + " motorbike");
11+
12+
13+
}
14+
vehicleType("blue",2);
15+

Week3/More-JS-5.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
//5 Can you write the following without the if statement, but with just as a single line with console.log(...);?
3+
/* if (3 === 3) {
4+
console.log("yes");
5+
} else {
6+
console.log("no");
7+
} */
8+
9+
3 === 3 ? console.log("yes"): console.log("no");

Week3/More-JS-6.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
/*6 Create a function called vehicle, like before,
3+
but takes another parameter called age,
4+
so that vehicle("blue", 1, 5) prints 'a blue used car'*/
5+
function vehicle(color,code,age){
6+
if (code==1 && age<2){
7+
console.log("a " + color + " new car")
8+
}
9+
else if (code==1 && age>2) {
10+
console.log("a " + color + " used car")
11+
}}
12+
vehicle("blue", 1, 5);

Week3/More-JS-7-8-9-10-11.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
//7 Make a list of vehicles, you can add "motorbike", "caravan", "bike", or more.
3+
let listOfVehicles = ["motorbike","caravan","bike"];
4+
5+
//8 How do you get the third element from that list?
6+
console.log(listOfVehicles[2]);
7+
8+
9+
10+
11+
/*9 Change the function vehicle to use the list of question 7.
12+
So that vehicle("green", 3, 1) prints "a green new bike".*/
13+
function Vehicles(color,code,age){
14+
if(code=listOfVehicles[2] && age<2){
15+
console.log("a " + color + " new bike")
16+
}
17+
else {
18+
console.log("a " + color + "old bike")
19+
};
20+
}
21+
Vehicles("green", 3, 1);
22+
23+
24+
/*10 Use the list of vehicles to write an advertisement.
25+
So that it prints something like:
26+
"Amazing Joe's Garage, we service cars, motorbikes, caravans and bikes.".
27+
(Hint: use a for loop.)
28+
Hint, the output should be correct English with all the punctuation in place
29+
(that's the challenge). So plurals for the vehicle types, commas followed by a single space,
30+
the word and to replace the final comma and closed off by a period. */
31+
32+
//11 What if you add one more vehicle to the list, can you have that added to the advertisement without changing the code for question 10?
33+
34+
listOfVehicles = ["motorbike","caravan","bike","car"];
35+
36+
function advertisement(listOfVehicles){
37+
for(let i=0; i<listOfVehicles.length; i++){
38+
console.log();
39+
}
40+
}
41+
advertisement(listOfVehicles); // stucked
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+

Week3/strings-arrays.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//1.Strings
2+
let myString = "hello,this,is,a,difficult,to,read,sentence";
3+
console.log(myString);
4+
myString=myString.replace(/,/g, " "); // that's totally google answer i couldn't find what the g stands for
5+
console.log(myString);
6+
7+
8+
9+
//2 Arrays
10+
let favoriteAnimals = ["blowfish", "capricorn", "giraffe"];
11+
// add Mauro's favorite animal 'turtle'
12+
favoriteAnimals[3]="turtle";
13+
console.log(favoriteAnimals);
14+
15+
16+
17+
//add Jim's favorite animal to the array, it's 'meerkat',to be placed after 'blowfish' and before 'capricorn'.
18+
favoriteAnimals.splice(favoriteAnimals.length/ 3, 0, "meerkat");
19+
console.log("blowfish", "meerkat", "capricorn", "giraffe", "turtle");
20+
console.log(favoriteAnimals);
21+
22+
23+
24+
// length of the array
25+
console.log("The array has a length of: " + favoriteAnimals.length);
26+
27+
28+
29+
// delete 'giraffe' from the array
30+
favoriteAnimals.splice(3, 1);
31+
console.log(favoriteAnimals);
32+
33+
34+
35+
36+
// how to find the position or the index of the item 'meerkat' in the array?
37+
console.log('The item you are looking for is at index: ' + favoriteAnimals.indexOf("meerkat"));

0 commit comments

Comments
 (0)