Skip to content

Commit e997d2e

Browse files
committed
Abdullah Al Ahmad- js1 - week3
1 parent 2a64083 commit e997d2e

File tree

10 files changed

+169
-1
lines changed

10 files changed

+169
-1
lines changed

Week2/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7-
<title>JS-week1</title>
7+
<title>JS-week2</title>
88
</head>
99
<body style ="text-align: center; padding: 10vw;">
1010
<h1 style="color: red; font: 3em sans-serif;">JS-week2</h1>

Week3/advertisement.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Use the list of vehicles to write an advertisement. So that it prints something like: "Amazing Joe's Garage, we service cars, motorbikes, caravans and bikes.". (Hint: use a for loop.)
2+
3+
// Hint, the output should be correct English with all the punctuation in place (that's the challenge). So plurals for the vehicle types, commas followed by a single space, the word and to replace the final comma and closed off by a period.
4+
5+
6+
let ad = "Amazing Joe's Garage, we service ";
7+
function advertisement (){
8+
for( i = 0 ; i < vehicles.length; i++){
9+
10+
if (i == vehicles.length-1){
11+
ad += 's' + ' and ' + vehicles[i] + 's' + '.';
12+
}else if(i == vehicles.length-2){
13+
ad += vehicles[i];
14+
}
15+
else { ad += vehicles[i]+ 's' + ', ' ;
16+
}
17+
}console.log(ad)
18+
}
19+
20+
// adding one vehicles to the list
21+
22+
vehicles.push('scooter');
23+
24+
advertisement();
25+
26+

Week3/arrays.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let favoriteAnimals = ["blowfish", "capricorn", "giraffe"];
2+
3+
favoriteAnimals.push('turtle');
4+
5+
console.log(favoriteAnimals);
6+
7+
favoriteAnimals.splice(1,0,'meerkat');
8+
9+
console.log('the value of the array will be 5 strings')
10+
11+
console.log(favoriteAnimals);
12+
13+
console.log('The array has a length of: ', favoriteAnimals.length)
14+
15+
favoriteAnimals.splice(3,1);
16+
17+
console.log(favoriteAnimals);
18+
19+
console.log('The item you are looking for is at index: ', favoriteAnimals.indexOf('meerkat'));
20+
21+
22+
23+

Week3/colorFun.js

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

Week3/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>JS-week3</title>
8+
</head>
9+
<body
10+
style ="text-align: center; padding: 10vw;">
11+
12+
<h1 style="color: red; font: 3em sans-serif;">JS-week3</h1>
13+
14+
<script src="strings.js"></script>`
15+
<script src="arrays.js"></script>
16+
<script src="sumFun.js"></script>
17+
<script src="colorFun.js"></script>
18+
<script src="vehicleType.js"></script>
19+
<script src="vehicle.js"></script>
20+
<script src="vehicleList.js"></script>
21+
<script src="advertisement.js"></script>
22+
23+
24+
<!--
25+
26+
<script src="roundNumber.js"></script>
27+
<script src="arrays.js"></script>
28+
<script src="moreStrings.js"></script>
29+
<script src="dataType.js"></script>
30+
<script src="%.js"></script>
31+
<script src="multiDataTypes.js"></script> -->
32+
33+
</body>
34+
</html>

Week3/strings.js

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

Week3/sumFun.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Create a function that takes 3 arguments and returns the sum of the these arguments.
2+
3+
function sum(){
4+
let sum =0;
5+
for(let i=0;i<arguments.length;i++){
6+
sum += arguments[i];
7+
}
8+
return sum;
9+
}
10+
console.log('1 + 2 =', sum(1,2)); // = 3
11+
console.log('1 + 8 + 3 =', sum(1,8,3)); // = 12
12+
13+

Week3/vehicle.js

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

Week3/vehicleList.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Make a list of vehicles, you can add "motorbike", "caravan", "bike", or more.
2+
3+
// How do you get the third element from that list?
4+
5+
// Change the function vehicle to use the list of question 7. So that vehicle("green", 3, 1) prints "a green new bike".
6+
7+
let vehicles = [' car', ' motorbike', ' bike', ' caraven' ];
8+
9+
function vehicleType(color,code, age){
10+
if (age < 1) {
11+
age = ' used'
12+
} else {
13+
age = ' new'
14+
}
15+
16+
if (code == 1){
17+
console.log('a ' + color + age + vehicles[0]);
18+
} else if (code == 2) {
19+
console.log('a ' + color + age + vehicles[1]);
20+
} else if (code == 3) {
21+
console.log('a ' + color + age + vehicles[2]);
22+
} else if (code == 4) {
23+
console.log('a ' + color + age + vehicles[3]);
24+
}
25+
26+
}
27+
28+
vehicleType('green', 3, 1);

Week3/vehicleType.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// 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)
2+
3+
function vehicleType(color,code){
4+
if (code == 1){
5+
console.log('a ' + color + ' car');
6+
} else if (code == 2) {
7+
console.log('a ' + color + ' motorbike');
8+
}
9+
}
10+
11+
12+
vehicleType('blue', 2);
13+

0 commit comments

Comments
 (0)