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

Skip to content

Commit ec3b2aa

Browse files
committed
upload week2 homework
1 parent ed98d81 commit ec3b2aa

19 files changed

+183
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

week2js/1strings.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let myString = "hello,this,is,a,difficult,to,read,sentence";
2+
console.log(myString);
3+
4+
let stringLength = myString.length;
5+
console.log(stringLength);
6+
7+
let myString_new = "hello " +"this "+ "is a " + "difficult " + "to read " + "sentence";
8+
console.log(myString_new);

week2js/2arrays.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let favoriteAnimals = ['blowfish', 'capricorn', 'giraffe'];
2+
console.log(favoriteAnimals);
3+
favoriteAnimals.push("turtle");
4+
console.log(favoriteAnimals);
5+
favoriteAnimals.splice(1, 0, "meerkat");
6+
console.log("I think the new value of the array is many favorite animals");
7+
console.log(favoriteAnimals);
8+
let favAnimalsLength = favoriteAnimals.length;
9+
console.log("The array has a length of: " + favAnimalsLength);
10+
favoriteAnimals.pop("giraffe");
11+
console.log(favoriteAnimals);
12+
let a = favoriteAnimals.indexOf("meerkat");
13+
console.log("The item you are looking for is at index: " + a );

week2js/3tada12_14.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// 12. empty object //
2+
const myObject = {}
3+
4+
// 13/ and 14. teachers //
5+
const myTeachers = {
6+
"Tommy": "HTML",
7+
"Chanchal": "HTML",
8+
"Victor": "CSS",
9+
"Rasmus": "Javascript",
10+
"Johann": "Javascript"
11+
};
12+
console.log(myTeachers);

week2js/3tada15_17.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//15.equality in arrays//
2+
let x = [1,2,3];
3+
let y = [1,2,3];
4+
let z = y;
5+
6+
function compare(a, b) {
7+
var i = a.length;
8+
if (i != b.length) return false;
9+
while (i--) {
10+
if (a[i] !== b[i]) return false;
11+
}
12+
return true;
13+
}
14+
console.log(compare(x, y));
15+
console.log(compare(z, y));
16+
console.log(compare(z, x));
17+
18+
19+
20+
//16. foo//
21+
let o1 = { foo: 'bar' };
22+
let o2 = { foo: 'bar' };
23+
let o3 = o2;
24+
console.log(o1);
25+
console.log(o2);
26+
console.log(o3);
27+
28+
o2.foo = 'chicken';
29+
console.log(o2);
30+
console.log(o3); // yes o3 has been changed//
31+
32+
// 17. type of//
33+
let bar = 42; // typeof bar would return number//
34+
console.log(typeof typeof bar); // returns string//
35+
36+
37+
38+
39+
40+

week2js/3tada1_5.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
//1. create a function //
3+
function sum(){
4+
let sum =0;
5+
for(var i=0;i<arguments.length;i++){
6+
sum += arguments[i];
7+
}
8+
return sum;
9+
}
10+
11+
console.log(sum(1, 2, 5));
12+
13+
//2. colorCar function//
14+
function colorCar(color){
15+
console.log("The " + color + " car");
16+
}
17+
colorCar("red");
18+
19+
//3.Object and function//
20+
let dog = {
21+
breed: "husky",
22+
name: "woof",
23+
age: 12,
24+
}
25+
function thisDog(obj){
26+
console.log(obj);
27+
}
28+
thisDog(dog);
29+
30+
31+
32+
//4. Vehicle Type//
33+
var code = (a === 2) ? "car":"motorbike";
34+
var color = "blue";
35+
function vehicleType(color, code){
36+
console.log("A " + color + " " + code);
37+
}
38+
vehicleType(color, code);
39+
40+
//5. single line //
41+
console.log(3 === 3) ? console.log("yes"): console.log("no");
42+
43+
44+

week2js/3tada6_11.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//6. vehicle //
2+
var code = (a === 2) ? "car":"motorbike";
3+
var color = "blue";
4+
var age = (age === 1) ? "new":"used";
5+
function vehicleType(color, age, code){
6+
console.log("A " + color + " " + age + " " + code);
7+
}
8+
vehicleType(color, age, code);
9+
10+
//7. list of vehicles//
11+
var vehicle = ["motorbike", "caravan", "bike", "scooter", "car", "truck"];
12+
console.log(vehicle);
13+
14+
//8 3rd element//
15+
console.log(vehicle[2]);
16+
17+
//9.function vehicle//
18+
function getVehicle(color, index, age){
19+
for(i =0; i<vehicleType.length; i++)
20+
if(index === i ){
21+
(age < 1) ? console.log("A " + color + " new " + age) : console.log("A " + color + " used " + age);
22+
}
23+
}
24+
getVehicle("Green", 2, vehicle[3]);
25+
26+
//10. advertisement//
27+
28+
29+
30+
function garage(){
31+
var advertisement = ("At Amazing Joe's Garage, we service: ");
32+
var last_item = vehicle[vehicle.length - 1];
33+
for (i = 0; i < vehicle.length; i++){
34+
if (i === 0) {
35+
console.log((advertisement) + vehicle[0] + "s,");
36+
} else if (i < vehicle.length - 1){
37+
console.log(vehicle[i] + "s,");
38+
} else {
39+
console.log("and " + (last_item) + "s.");
40+
}
41+
}
42+
}
43+
garage();
44+
45+
46+
47+
/* 11. What if you add one more vehicle to the list,
48+
can you have that added to the advertisement
49+
without changing the code for question 10?/*/
50+
vehicle.push("rickshaw");
51+
garage();

week2js/dummy.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<script src ="1strings.js"></script>
4+
<script src ="2arrays.js"></script>
5+
<script src ="3tada1_5.js"></script>
6+
<script src ="3tada6_11.js"></script>
7+
<script src ="3tada12_14.js"></script>
8+
<script src ="3tada15_17.js"></script>
9+
10+
</head>
11+
<body>
12+
13+
</body>
14+
15+
</html>

0 commit comments

Comments
 (0)