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

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Abdullah Al Ahmad #114

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Week2/%.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Explaining %

x = 12;
console.log(x);

console.log ('x % 5 will be 2 which is the leftover number that cannot be divided on 5');

console.log(x % 5);
15 changes: 15 additions & 0 deletions Week2/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Animals Names

let myFavoriteAnimals;

console.log('The value of myFavoriteAnimals is: undefined then an object \'array\' ');

console.log(myFavoriteAnimals);

myFavoriteAnimals = ['monkey', 'horse', 'turtle'];

console.log(myFavoriteAnimals);

myFavoriteAnimals = myFavoriteAnimals + [', baby pig'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use myFavoriteAnimals.push('baby pig')'. This will work but it's not the correct way to do this.


console.log(myFavoriteAnimals);
61 changes: 61 additions & 0 deletions Week2/dataType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Types of Data

let success = 'Congats! the data type of your variables is identical!';

console.log(success + ' * this is a string');

console.log(typeof success);


let failure = 'Oops! the data type of your variables is different!';

console.log(failure + ' * this is a string');

console.log(typeof failure);


let number = 1;

console.log(number + ' * this is a number');

console.log(typeof number);


let boolean = true;

console.log(boolean + ' * this is a boolean');

console.log(typeof boolean);


let array = [0, 1, 2, 3, 4];

console.log(array + ' * this is an object');

console.log(typeof array);

// Testing type of data

if (typeof success === typeof failure) {

console.log(success);

} else {
console.log(failure);
}


if (typeof success === typeof number) {
console.log(success);

} else {
console.log(failure);
}


if (typeof boolean === typeof array) {
console.log(success);

} else {
console.log(failure);
}
11 changes: 11 additions & 0 deletions Week2/helloWorld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Greetings

console.log ('Hello World!'); //English

console.log ('Halo, Dunia!'); // Indonesian

console.log ('Ciao Mondo!'); // Italian

console.log ('Hola Mundo!'); // Spanish


17 changes: 17 additions & 0 deletions Week2/imAwesome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Debug single quote issue

console.log('I\'m awesome');

// variables & Values

let x;

console.log("the value of my variable x will be: undefined ");

console.log(x);

x = 12;

console.log("the value of my variable x will be: a number 12 ");

console.log(x);
30 changes: 30 additions & 0 deletions Week2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JS-week2</title>
</head>
<body style ="text-align: center; padding: 10vw;">
<h1 style="color: red; font: 3em sans-serif;">JS-week2</h1>
<script src="helloWorld.js"></script>
<script src="imAwesome.js"></script>
<script src="tom&jerry.js"></script>
<script src="roundNumber.js"></script>
<script src="arrays.js"></script>
<script src="moreStrings.js"></script>
<script src="dataType.js"></script>
<script src="%.js"></script>
<script src="multiDataTypes.js"></script>









</body>
</html>
7 changes: 7 additions & 0 deletions Week2/moreStrings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// String Length

let myString = "this is a test";

console.log(myString);

console.log(myString.length);
16 changes: 16 additions & 0 deletions Week2/multiDataTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Array with multiple data types

console.log('following array contains 2 numbers, 2 strings and a boolean');

let multipleTypesArray = [0, 'hero', 2, 'too', false];

console.log(multipleTypesArray);

// Comparing infinities

if (10/0 === 6/0) {
console.log('Yes! they\'re equal!');

} else {
console.log('There\'s no equality in this!');
}
24 changes: 24 additions & 0 deletions Week2/roundNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

let z = 7.25;

console.log(z);

// Round z to the closest integer

let round = Math.round;

let a = round(z);

console.log(a);

// Print higher value z or a

if (a<z) {
let i = z;
console.log(i);

} else {
let i = a;
console.log(i);

}
11 changes: 11 additions & 0 deletions Week2/tom&jerry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let y = 'Tom';

console.log("the value of my string y will be: a string");

console.log(y);

y = y + '&Jerry';

console.log("the value of my string y will be: a string");

console.log(y);
26 changes: 26 additions & 0 deletions Week3/advertisement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.)

// 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.


let ad = "Amazing Joe's Garage, we service ";
function advertisement (){
for( i = 0 ; i < vehicles.length; i++){

if (i == vehicles.length-1){
ad += 's' + ' and ' + vehicles[i] + 's' + '.';
}else if(i == vehicles.length-2){
ad += vehicles[i];
}
else { ad += vehicles[i]+ 's' + ', ' ;
}
}console.log(ad)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, it would be more readable if you add more spaces and align your brackets ({), like this:

And I would advise to put the code of 's' + ' and ' not in that part, but always add the s in the other if statement. It's difficult to explain so here is the code of what I mean:

let ad = "Amazing Joe's Garage, we service ";
function advertisement (){
    for( i = 0 ; i < vehicles.length; i++){
      if (i == vehicles.length-1) {
        ad += ' and ' + vehicles[i] + 's' + '.';
      } else if(i == vehicles.length-2) {
         ad += vehicles[i]; + 's' 
      } else { 
        ad += vehicles[i]+ 's' +  ', ' ;
      }
   }
 console.log(ad);
}


// adding one vehicles to the list

vehicles.push('scooter');

advertisement();


23 changes: 23 additions & 0 deletions Week3/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let favoriteAnimals = ["blowfish", "capricorn", "giraffe"];

favoriteAnimals.push('turtle');

console.log(favoriteAnimals);

favoriteAnimals.splice(1,0,'meerkat');

console.log('the value of the array will be 5 strings')

console.log(favoriteAnimals);

console.log('The array has a length of: ', favoriteAnimals.length)

favoriteAnimals.splice(3,1);

console.log(favoriteAnimals);

console.log('The item you are looking for is at index: ', favoriteAnimals.indexOf('meerkat'));




7 changes: 7 additions & 0 deletions Week3/colorFun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Create a function named colorCar that receives a color, and prints out, 'a red car' for example.

function colorCar(color){
console.log('a ' + color + ' car');
}

colorCar('red');
34 changes: 34 additions & 0 deletions Week3/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JS-week3</title>
</head>
<body
style ="text-align: center; padding: 10vw;">

<h1 style="color: red; font: 3em sans-serif;">JS-week3</h1>

<script src="strings.js"></script>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot some parts of the homework?

I think assignment 12 untill 16 are missing, see the homework

<script src="arrays.js"></script>
<script src="sumFun.js"></script>
<script src="colorFun.js"></script>
<script src="vehicleType.js"></script>
<script src="vehicle.js"></script>
<script src="vehicleList.js"></script>
<script src="advertisement.js"></script>


<!--

<script src="roundNumber.js"></script>
<script src="arrays.js"></script>
<script src="moreStrings.js"></script>
<script src="dataType.js"></script>
<script src="%.js"></script>
<script src="multiDataTypes.js"></script> -->

</body>
</html>
6 changes: 6 additions & 0 deletions Week3/strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let myString = "hello,this,is,a,difficult,to,read,sentence";

console.log(myString.length);

console.log(myString.replace(/,/g," "));

13 changes: 13 additions & 0 deletions Week3/sumFun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Create a function that takes 3 arguments and returns the sum of the these arguments.

function sum(){
let sum =0;
for(let i=0;i<arguments.length;i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this is correct, but I think that the assignment meant that you explicitly define three arguments and combine those. but I guess you know how to do that, since you've done it in a more complex way. So it's okay

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tip: This is a pretty clever solution actually. But more difficult in use for other programmers if you collaborate on the code, because it is not intuitive for someone to know how many arguments they have to pass to the function and what will happen to them. So this is just a tip for the future, this solution is clever but not really good if you are collaborating with other programmers.

sum += arguments[i];
}
return sum;
}
console.log('1 + 2 =', sum(1,2)); // = 3
console.log('1 + 8 + 3 =', sum(1,8,3)); // = 12


18 changes: 18 additions & 0 deletions Week3/vehicle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Create a function called vehicle, like before, but takes another parameter called age, so that vehicle("blue", 1, 5) prints 'a blue used car'

function vehicleType(color,code, age){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also correct, but it's not a good practice to modify the arguments that are passed in the function. Because if you modify a property of that argument in the function, it will also change the property for that argument outside the function. I know this is not the case in this specific function, but it could happen in the future, which could lead to confusing results. For example:

function vehicleType(color,code, anObject){
    if (anObject.age < 1) {
        anObject.age = 'bused'
    } else {
       anObject.age = ' new'
    }

    if (code == 1){
        console.log('a ' + color + anObject.age + ' car');
    } else if (code == 2) {
        console.log('a ' + color + anObject.age + ' motorbike');
    }
}

let color = "green";
let code = 1;
let anObject = { age: 12, name: "test" };

console.log("before the function, the age is " + anObject.age);
vehicleType(color, code, anObject);
console.log("after the first function, the age is " + anObject.age);

In this code example, the property age is modified in the function, which affects the anObject variable, which is outside the function.

if (age < 1) {
age = 'bused'
} else {
age = ' new'
}

if (code == 1){
console.log('a ' + color + age + ' car');
} else if (code == 2) {
console.log('a ' + color + age + ' motorbike');
}

}

vehicleType('blue', 2, 5);
28 changes: 28 additions & 0 deletions Week3/vehicleList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Make a list of vehicles, you can add "motorbike", "caravan", "bike", or more.

// How do you get the third element from that list?

// Change the function vehicle to use the list of question 7. So that vehicle("green", 3, 1) prints "a green new bike".

let vehicles = [' car', ' motorbike', ' bike', ' caraven' ];

function vehicleType(color,code, age){
if (age < 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the same remark as above (about the bad practice to modify an argument that is passed in the function)

age = ' used'
} else {
age = ' new'
}

if (code == 1){
console.log('a ' + color + age + vehicles[0]);
} else if (code == 2) {
console.log('a ' + color + age + vehicles[1]);
} else if (code == 3) {
console.log('a ' + color + age + vehicles[2]);
} else if (code == 4) {
console.log('a ' + color + age + vehicles[3]);
}

}

vehicleType('green', 3, 1);
13 changes: 13 additions & 0 deletions Week3/vehicleType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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)

function vehicleType(color,code){
if (code == 1){
console.log('a ' + color + ' car');
} else if (code == 2) {
console.log('a ' + color + ' motorbike');
}
}


vehicleType('blue', 2);