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

Skip to content

Commit ebdf60a

Browse files
committed
upload after homework session at HYF
1 parent a278045 commit ebdf60a

File tree

9 files changed

+107
-25
lines changed

9 files changed

+107
-25
lines changed

week1js/10program.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
var program = [23, "this is a string", 13, "yellow",];
22
console.log(program);
3+
console.log("Yes you can:", program);
34

5+
/*my answer, better answer is below
46
var compare = 6/0 === 10/0;
57
console.log(compare);
6-
var compareneg = -6/0 === 10/0;
7-
console.log(compareneg);
8+
var compareNeg = -6/0 === 10/0;
9+
console.log(compareneg);*/
10+
11+
function compares(x, y){
12+
if (x /0 === y/0){
13+
console.log("Yes they are the same");
14+
console.log(x / y);
15+
} else {
16+
console.log("no they are not equal");
17+
}
18+
}
19+
compares(6, 10);

week1js/8sametype.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ var type_c = typeof x;
1818
var type_d = typeof null;
1919

2020
if( type_a == type_b | type_c | type_d)
21-
{console.log('SAME TYPE');}
21+
{console.log('SAME TYPE');}
2222
else
2323
{console.log('DIFFERENT TYPE');}
2424

25+
/*this is not completely correct, there should be an if loop for every comparison, not 'just type a' being
26+
compared to each of the other types. You could also use a for loop*/

week1js/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<script src ="3variablex.js"></script>
1212
<script src ="2Imawesome.js"></script>
1313
<script src ="1hworldlanguages.js"></script>
14-
<script src = "dummy.js"></script>
14+
1515
</head>
1616
<body>
1717
hello world

week2js/1strings.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ let stringLength = myString.length;
55
console.log(stringLength);
66

77
let myString_new = "hello " +"this "+ "is a " + "difficult " + "to read " + "sentence";
8-
console.log(myString_new);
8+
console.log(myString_new);
9+
10+
//alternative, better way to do it://
11+
myString = myString.replace(/,/g, " ");
12+
console.log(myString);
13+
14+
//note: the /g means to use 'global' scope. if you didn't put this in, only the hello is separated with a space//
15+

week2js/2arrays.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ let favoriteAnimals = ['blowfish', 'capricorn', 'giraffe'];
22
console.log(favoriteAnimals);
33
favoriteAnimals.push("turtle");
44
console.log(favoriteAnimals);
5+
56
favoriteAnimals.splice(1, 0, "meerkat");
67
console.log("I think the new value of the array is many favorite animals");
78
console.log(favoriteAnimals);
9+
// 0 here means: do not delete anything, ie splice, what is going in, what is going out....//
10+
//..we are putting something in at position 1, but we are not taking anything out, ie 0//
11+
812
let favAnimalsLength = favoriteAnimals.length;
913
console.log("The array has a length of: " + favAnimalsLength);
10-
favoriteAnimals.pop("giraffe");
14+
favoriteAnimals.splice(3, 1);
1115
console.log(favoriteAnimals);
16+
/*if you used pop here it would only delete the last animal. use splice here because giraffe is not the
17+
last item and that is what you to delete*/
18+
1219
let a = favoriteAnimals.indexOf("meerkat");
1320
console.log("The item you are looking for is at index: " + a );

week2js/3tada12_14.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// 12. empty object //
2-
const myObject = {}
2+
let obj = {};
3+
console.log(obj);
34

45
// 13/ and 14. teachers //
56
const myTeachers = {
@@ -8,5 +9,8 @@ const myTeachers = {
89
"Victor": "CSS",
910
"Rasmus": "Javascript",
1011
"Johann": "Javascript"
11-
};
12-
console.log(myTeachers);
12+
}
13+
console.log(myTeachers);
14+
15+
16+

week2js/3tada15_17.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@ let x = [1,2,3];
33
let y = [1,2,3];
44
let z = y;
55

6-
function compare(a, b) {
6+
x == y ? console.log("equal") : console.log("not equal");
7+
x === y ? console.log("equal") : console.log("not equal");
8+
z == x ? console.log("equal") : console.log("not equal");
9+
z === x ? console.log("equal") : console.log("not equal");
10+
z == y ? console.log("equal") : console.log("not equal");
11+
z === y ? console.log("equal") : console.log("not equal");
12+
/*Why is these equal/not equal? because x and y might have the same looking info in it, they are not the same objects.
13+
but z and y do have the same objects, because they are both just pointers pointing to the same box.
14+
x and y are both pointing to two different boxes which both happen to have the same info in it.*/
15+
16+
17+
/*assigning variable by content or reference , ie z = y is saying that z has the same 'address' as y does.//
18+
ie they both point to the same box, with the box being the [] stuff
19+
note: x does not equal y in this case because they do not point to the same object.
20+
ie: their objects look the same, but they are two different boxes, whilst z is only pointing to y's box,
21+
it is not actually making a whole new box for z */
22+
/*THIS CODE DOESN'T OUTPUT THE RIGHT INFO. THE LAST SHOULD BE FALSE */
23+
24+
25+
/*function compare(a, b) {
726
var i = a.length;
827
if (i != b.length) return false;
928
while (i--) {
@@ -13,7 +32,7 @@ function compare(a, b) {
1332
}
1433
console.log(compare(x, y));
1534
console.log(compare(z, y));
16-
console.log(compare(z, x));
35+
console.log(compare(z, x));*/
1736

1837

1938

@@ -28,6 +47,8 @@ console.log(o3);
2847
o2.foo = 'chicken';
2948
console.log(o2);
3049
console.log(o3); // yes o3 has been changed//
50+
/* this is the same as question 15, o2 and o3 both point to the same box. so when you change the box
51+
contents, both o2 and o3 change because they are both pointing to that box.*/node
3152

3253
// 17. type of//
3354
let bar = 42;

week2js/3tada1_5.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,42 @@ function sum(){
99
}
1010

1111
console.log(sum(1, 2, 5));
12+
13+
/* someone elses response to question 1:
14+
var a, b, c;
15+
function sumOfThree(a,b,c){
16+
console.log(a+b+c);
17+
}
18+
sumOfThree(1, 'b', 3);
19+
sumOfThree('ab', 'c', 'd');*/
20+
1221

1322
//2. colorCar function//
1423
function colorCar(color){
1524
console.log("The " + color + " car");
1625
}
1726
colorCar("red");
27+
colorCar("orange");
1828

1929
//3.Object and function//
2030
let dog = {
2131
breed: "husky",
22-
name: "woof",
32+
name: "Roger",
2333
age: 12,
2434
}
2535
function thisDog(obj){
2636
console.log(obj);
2737
}
2838
thisDog(dog);
29-
30-
31-
32-
//4. Vehicle Type//
39+
/*so when the let variable 'dog' was created, it became a list by the way that the
40+
information was entered, ie name: age: etc). then the function asks that we print an obj when it is called
41+
ie the command is : console.log(obj). so the functions' purpose is to print an object when
42+
'thisDog' is called.
43+
the object is not yet identified, it could be any object. when we call the function
44+
we put the name of the object in the brackets, which in this case is 'dog'
45+
so: thisDog(dog); will print out whatever is within the object called 'dog'. */
46+
47+
//4. Vehihcle Type//
3348
var code = (a === 2) ? "car":"motorbike";
3449
var color = "blue";
3550
function vehicleType(color, code){
@@ -39,6 +54,9 @@ vehicleType(color, code);
3954

4055
//5. single line //
4156
console.log(3 === 3) ? console.log("yes"): console.log("no");
57+
/* or you can write it like this:
58+
console.log(3 === 3 ? "yes" : "no");
59+
it will do the same thing as above*/
4260

4361

4462

week2js/3tada6_11.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
//6. vehicle //
2-
var code = (a === 2) ? "car":"motorbike";
3-
var color = "blue";
1+
//6. vehicle
2+
3+
4+
var vehicle = ["motorbike", "caravan", "bike", "scooter", "car", "truck"];
45
var age = (age === 1) ? "new":"used";
5-
function vehicleType(color, age, code){
6-
console.log("A " + color + " " + age + " " + code);
6+
7+
console.log(vehicle[5]);
8+
function vehicleType(color, age, vehicle){
9+
console.log("A " + color + " " + age + " " + vehicle);
710
}
8-
vehicleType(color, age, code);
11+
vehicleType("pink", "used", "car");
912

1013
//7. list of vehicles//
11-
var vehicle = ["motorbike", "caravan", "bike", "scooter", "car", "truck"];
1214
console.log(vehicle);
1315

1416
//8 3rd element//
@@ -23,9 +25,18 @@ function getVehicle(color, index, age){
2325
}
2426
getVehicle("Green", 2, vehicle[3]);
2527

26-
//10. advertisement//
27-
28+
/*try this code:
29+
function vehicles(color, code, age) {
30+
if (age > 1){
31+
console.log( 'a ' + color + ' used ' +list[code])
32+
} else if (age <= 1){
33+
console.log('a ' + color + ' new ' + list[code])
34+
}
35+
}
36+
console.log("vehicle('green', 3, 1) ===> " + vehicle("green", 3, 1));
37+
vehicles("green", 3, 1);*/
2838

39+
//10. advertisement//
2940

3041
function garage(){
3142
var advertisement = ("At Amazing Joe's Garage, we service: ");

0 commit comments

Comments
 (0)