Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
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/arraysTask-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const str = 'dlroW olleH';
console.log('my string is: '+str);
const splitString = str.split('');
console.log('make it array: '+splitString);
const reverseArray = splitString.reverse();
console.log('reverse array: '+reverseArray);
const joinArray = reverseArray.join('');
console.log('corrected string is: '+joinArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

Very well. The logic is correct but you can also reduce it in a single statement using a programming practice called method chaining. For example,

const str = 'dlroW olleH';
const reversedString = str.split('').reverse().join('');

Here I have merged all three operations in a single statement using method chaining.

Copy link
Author

Choose a reason for hiding this comment

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

Oh! It's a very great way! Thank you to show me.

8 changes: 8 additions & 0 deletions Week2/homework/arraysTask-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const str = 'dlroW olleH';
console.log('my string is: '+str);
const splitString = str.split('');
console.log('make it array: '+splitString);
const reverseArray = splitString.reverse();
console.log('reverse array: '+reverseArray);
const joinArray = reverseArray.join('');
console.log('corrected string is: '+joinArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering why did you have to repeat this homework submission here? I remember that you were unable to make it to the Week1 where we covered Gitflow in a bit more detail. Let me or Tjebbe know please if you have any confusions or questions around working with Git and we can perhaps work on something. 🙂

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I did it accidentally then I figured out how to correctly use all this git system.

4 changes: 4 additions & 0 deletions Week2/homework/stringsTask-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const myString = "hello,this,is,a,difficult,to,read,sentence";
console.log('my string is: '+myString);
console.log('length of the string is: '+myString.length+' characters');
console.log('corrected string is: '+myString.replace(/,/g,' '));
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for logic. I would also like to introduce a new feature in JavaScript ES6 called template literals. It can be found here - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Using template literals allows you to combine variables and strings and avoid using + operator to concatenate strings.

`corrected string is: ${myString.replace(/,/g, ' '});`

Copy link
Author

Choose a reason for hiding this comment

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

I already start to use them. And I love it!

8 changes: 8 additions & 0 deletions Week2/homework/stringsTask-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const str = 'dlroW olleH';
console.log('my string is: '+str);
const splitString = str.split('');
console.log('make it array: '+splitString);
const reverseArray = splitString.reverse();
console.log('reverse array: '+reverseArray);
const joinArray = reverseArray.join('');
console.log('corrected string is: '+joinArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

This again? 🤔

6 changes: 6 additions & 0 deletions Week2/homework/task01HelloWorld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function helloWorld (greetings, language) {
console.log ( greetings + ' // ' + language)
};
helloWorld ('Halo, dunia!', 'Indonesian');
helloWorld ('Ciao, mondo!', 'Italian');
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice of you to create a function for this purpose. 👏

However, there is a slight indentation problem on line 3. 🙂

Copy link
Author

Choose a reason for hiding this comment

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

extra tab?


1 change: 1 addition & 0 deletions Week2/homework/task02SyntaxError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("I'm awesome");
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

6 changes: 6 additions & 0 deletions Week2/homework/task03IntegerVariable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let x;
console.log("the value of my variable x will be: 13");
console.log(x);
x=13;
Copy link
Contributor

Choose a reason for hiding this comment

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

A very small thing to improve is space between words like - x = 13;

Copy link
Author

Choose a reason for hiding this comment

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

I got it.

console.log("the value of my variable x will be: 13");
console.log(x);
6 changes: 6 additions & 0 deletions Week2/homework/task04StringVariable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let y = 'dog';
console.log("the value of my variable x will be: cat");
console.log(y);
y='cat';
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above about spacing 🙂

Copy link
Author

Choose a reason for hiding this comment

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

yep

console.log("the value of my variable x will be: cat");
console.log(y);
10 changes: 10 additions & 0 deletions Week2/homework/task05RoundNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let z = 7.25;
console.log(z);
let a = Math.round(z);
console.log(a);
if (z < a) {
fin = a;
} else {
fin = z;
};
console.log(fin);
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple things to improve here:

  1. You didn't declare variable fin anywhere in this file. This means JavaScript will create fin as a global variable which is not nice 😱
  2. Indentation problem here. Better if it is like this:
if (z < a) {
  fin = a;
} else {
  fin = z;
}

7 changes: 7 additions & 0 deletions Week2/homework/task06FavoriteAnimalsArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let animals = [];
console.log("the value of my array is: cat, dog, rabbit, bird");
console.log(animals);
Copy link
Contributor

Choose a reason for hiding this comment

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

Err! animals is an empty array here.

Copy link
Author

Choose a reason for hiding this comment

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

I thought it's a part of the task.

let myFavoriteAnimals = ['cat', 'dog', 'rabbit', 'bird'];
console.log(myFavoriteAnimals);
myFavoriteAnimals.push('baby pig');
console.log(myFavoriteAnimals);
2 changes: 2 additions & 0 deletions Week2/homework/task07StringLength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let myString = "this is a test";
console.log(myString.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

33 changes: 33 additions & 0 deletions Week2/homework/task08VariablesTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
x = 13;
y = 'cow';
z = true;
c = 26;
console.log("The value of my variable x is: " + x);
console.log("The value of my variable x is: " + y);
console.log("The value of my variable x is: " + z);
console.log("The value of my variable x is: " + c);
console.log("I think the types of my variables are all different");
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things here:

  1. You didn't use any keyword like var, let or const while creating these variables. It's a bad practice to do so. Please take care next time onwards. 🙂
  2. Types of variables x and c would the same i.e number 😉

Copy link
Author

Choose a reason for hiding this comment

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

  1. I was so young and green.
  2. So it was conceived.

console.log(typeof x);
console.log(typeof y);
console.log(typeof z);
console.log(typeof c);
if (typeof x===typeof y) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm.. I wonder why there is indentation problem when you are using if-else blocks. 🤔

Also, make sure you include spaces which makes code more readable. Something like:

(typeof x === typeof y)

Copy link
Author

Choose a reason for hiding this comment

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

ok

console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
if (typeof y===typeof z) {
console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
if (typeof z===typeof c) {
console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
if (typeof c===typeof x) {
console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
7 changes: 7 additions & 0 deletions Week2/homework/task09RemainerOfDividing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x = 7;
x = x % 3;
console.log (x);
y = 6;
console.log ('remainer of 6 / 2 is ' + y % 2);
z = 14;
console.log ('remainer of 13 / 4 is ' + z % 4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Only missing thing here is using var, let or const to create variables.

6 changes: 6 additions & 0 deletions Week2/homework/task10ComparesingNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let x = [13, 'cow', {}, [], true, null];
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI - if you are not going to reassign a variable later in the code(x in this case), it's generally a good practice to use const instead of let or var. 🙂

Copy link
Author

Choose a reason for hiding this comment

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

I got it. Thanks.

console.log('You can store multiple types in array. For example, array "x" contains ' + x);
console.log('-Infinity equals +Infinity; This is');
console.log(-Infinity===+Infinity);
console.log('6/0 equals 10/0; This is');
console.log(6/0===10/0);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

4 changes: 4 additions & 0 deletions Week2/stringsTask-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const myString = "hello,this,is,a,difficult,to,read,sentence";
console.log('my string is: '+myString);
console.log('length of the string is: '+myString.length+' characters');
console.log('corrected string is: '+myString.replace(/,/g,' '));
8 changes: 8 additions & 0 deletions Week2/stringsTask-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const str = 'dlroW olleH';
console.log('my string is: '+str);
const splitString = str.split('');
console.log('make it array: '+splitString);
const reverseArray = splitString.reverse();
console.log('reverse array: '+reverseArray);
const joinArray = reverseArray.join('');
console.log('corrected string is: '+joinArray);
6 changes: 6 additions & 0 deletions Week2/task01HelloWorld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function helloWorld (greetings, language) {
console.log ( greetings + ' // ' + language)
};
helloWorld ('Halo, dunia!', 'Indonesian');
helloWorld ('Ciao, mondo!', 'Italian');

1 change: 1 addition & 0 deletions Week2/task02SyntaxError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("I'm awesome");
6 changes: 6 additions & 0 deletions Week2/task03IntegerVariable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let x;
console.log("the value of my variable x will be: 13");
console.log(x);
x=13;
console.log("the value of my variable x will be: 13");
console.log(x);
6 changes: 6 additions & 0 deletions Week2/task04StringVariable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let y = 'dog';
console.log("the value of my variable x will be: cat");
console.log(y);
y='cat';
console.log("the value of my variable x will be: cat");
console.log(y);
10 changes: 10 additions & 0 deletions Week2/task05RoundNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let z = 7.25;
console.log(z);
let a = Math.round(z);
console.log(a);
if (z < a) {
fin = a;
} else {
fin = z;
};
console.log(fin);
7 changes: 7 additions & 0 deletions Week2/task06FavoriteAnimalsArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let animals = [];
console.log("the value of my array is: cat, dog, rabbit, bird");
console.log(animals);
let myFavoriteAnimals = ['cat', 'dog', 'rabbit', 'bird'];
console.log(myFavoriteAnimals);
myFavoriteAnimals.push('baby pig');
console.log(myFavoriteAnimals);
2 changes: 2 additions & 0 deletions Week2/task07StringLength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let myString = "this is a test";
console.log(myString.length);
33 changes: 33 additions & 0 deletions Week2/task08VariablesTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
x = 13;
y = 'cow';
z = true;
c = 26;
console.log("The value of my variable x is: " + x);
console.log("The value of my variable x is: " + y);
console.log("The value of my variable x is: " + z);
console.log("The value of my variable x is: " + c);
console.log("I think the types of my variables are all different");
console.log(typeof x);
console.log(typeof y);
console.log(typeof z);
console.log(typeof c);
if (typeof x===typeof y) {
console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
if (typeof y===typeof z) {
console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
if (typeof z===typeof c) {
console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
if (typeof c===typeof x) {
console.log('SAME TYPE');
} else {
console.log('different TYPEs');
};
7 changes: 7 additions & 0 deletions Week2/task09RemainerOfDividing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x = 7;
x = x % 3;
console.log (x);
y = 6;
console.log ('remainer of 6 / 2 is ' + y % 2);
z = 14;
console.log ('remainer of 13 / 4 is ' + z % 4);
6 changes: 6 additions & 0 deletions Week2/task10ComparesingNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let x = [13, 'cow', {}, [], true, null];
console.log('You can store multiple types in array. For example, array "x" contains ' + x);
console.log('-Infinity equals +Infinity; This is');
console.log(-Infinity===+Infinity);
console.log('6/0 equals 10/0; This is');
console.log(6/0===10/0);
4 changes: 4 additions & 0 deletions Week3/task01ReplaceCharactersInStrings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const myString = "hello,this,is,a,difficult,to,read,sentence";
console.log('my string is: '+myString);
console.log('length of the string is: '+myString.length+' characters');
console.log('corrected string is: '+myString.replace(/,/g,' '));
4 changes: 4 additions & 0 deletions Week3/task01Strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const myString = "hello,this,is,a,difficult,to,read,sentence";
console.log('my string is: '+myString);
console.log('length of the string is: '+myString.length+' characters');
console.log('corrected string is: '+myString.replace(/,/g,' '));
27 changes: 27 additions & 0 deletions Week3/task02AddDeleteElementsInArrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let favoriteAnimals = ["blowfish", "capricorn", "giraffe"];
console.log('an array is: '+favoriteAnimals);
function mauroFavoriteAnimal() {
favoriteAnimals.splice([favoriteAnimals.length], 0, 'turtle');
console.log('a new array is: '+favoriteAnimals);
};
mauroFavoriteAnimal();
function jimFavoriteAnimal() {
favoriteAnimals.splice(1, 0, 'meerkat');
console.log('a new array is: '+favoriteAnimals);
};
jimFavoriteAnimal();
console.log("I think this line is very strange. I don't know why am I writing it :(");
console.log('The array has a length of: '+favoriteAnimals.length);
function deleteGiraffe() {
let giraffe = favoriteAnimals.indexOf("giraffe");
favoriteAnimals.splice([giraffe], 1);
console.log('a new array is: '+favoriteAnimals);
};
deleteGiraffe();
function deleteMeerkat() {
let meerkat = favoriteAnimals.indexOf("meerkat");
console.log('The item you are looking for is at index: '+meerkat);
favoriteAnimals.splice([meerkat], 1);
console.log('a new array is: '+favoriteAnimals);
};
deleteMeerkat();
27 changes: 27 additions & 0 deletions Week3/task02Arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let favoriteAnimals = ["blowfish", "capricorn", "giraffe"];
console.log('an array is: '+favoriteAnimals);
function mauroFavoriteAnimal() {
favoriteAnimals.splice([favoriteAnimals.length], 0, 'turtle');
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use favoriteAnimals.push('turtle'); instead.

Copy link
Author

Choose a reason for hiding this comment

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

ok

console.log('a new array is: '+favoriteAnimals);
};
mauroFavoriteAnimal();
function jimFavoriteAnimal() {
favoriteAnimals.splice(1, 0, 'meerkat');
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

console.log('a new array is: '+favoriteAnimals);
};
jimFavoriteAnimal();
console.log("I think this line is very strange. I don't know why am I writing it :(");
console.log('The array has a length of: '+favoriteAnimals.length);
function deleteGiraffe() {
let giraffe = favoriteAnimals.indexOf("giraffe");
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use const here instead of let.

Copy link
Author

Choose a reason for hiding this comment

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

ok

favoriteAnimals.splice([giraffe], 1);
console.log('a new array is: '+favoriteAnimals);
};
deleteGiraffe();
function deleteMeerkat() {
let meerkat = favoriteAnimals.indexOf("meerkat");
console.log('The item you are looking for is at index: '+meerkat);
favoriteAnimals.splice([meerkat], 1);
console.log('a new array is: '+favoriteAnimals);
};
deleteMeerkat();
7 changes: 7 additions & 0 deletions Week3/task03SumOfArguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let x;
function abcSum(a,b,c) {
x = a + b + c;
return x;
};
abcSum(1,2,3);
Copy link
Contributor

Choose a reason for hiding this comment

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

Aahaan. This isn't the best way of dealing this situation. When we write functions in JavaScript, we should try to use only function parameters or local function variables instead of relying on variables outside the function's scope. Thus, using x here isn't ideal as it belongs outside the function's scope. A better way to do this would be:

function abcSum(a,b,c) {
    const x = a + b + c;
    return x;
};
console.log(abcSum(1,2,3));

Copy link
Author

Choose a reason for hiding this comment

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

Now I understand. Thank you.

console.log(x);
4 changes: 4 additions & 0 deletions Week3/task04ColorCar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function colorCar(color) {
console.log('a '+color+' car');
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

};
colorCar('red');
14 changes: 14 additions & 0 deletions Week3/task05ObjectProperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let person = {
Copy link
Contributor

Choose a reason for hiding this comment

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

const here instead of let 🙂

Copy link
Author

Choose a reason for hiding this comment

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

ok

firstname:"John",
lastname:"Doe",
age:50,
eyecolor:"blue"
};
function showProVa() {
console.log('Parameters of an object is '+Object.getOwnPropertyNames(person));
console.log('The actual values of the parameters is:');
let x;
for (x in person) {
console.log(person[x]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm.. I think a better way to do this would be like this:

function showPropValue(obj) {
  for (const prop in obj) {
    console.log(obj[prop]);
  }
}

showPropValue(person);

What do you think? Can you see some advantages of writing a function like this?

Copy link
Author

Choose a reason for hiding this comment

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

Well, I think I wrote pretty the same function. The only difference is that my function shows not only values but names of properties also. As it was asked in a task.

};};
showProVa();
8 changes: 8 additions & 0 deletions Week3/task06VehicleBeginning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function vehicleType(color, code) {
if (code === 1) {
console.log('a '+color+' car');
} else {
console.log('a '+color+' motorbike');
};
};
vehicleType("blue",2);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

1 change: 1 addition & 0 deletions Week3/task07SingleLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log( 3 === 3 ? 'yes' : 'no');
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

21 changes: 21 additions & 0 deletions Week3/task08Vehicles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const vehicleCodes = ['plane', 'car', 'motorbike','caravan','bike'];

function vehicle(color, code, age) {
const valueOfColor = color;
const valueOfCode = vehicleCodes[code];
const valueOfAge = age <= 1 ? 'new' : 'used';
Copy link
Contributor

Choose a reason for hiding this comment

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

Good use of conditional operator here 👍

console.log('a '+valueOfColor, valueOfAge, valueOfCode)
};
vehicle("green", 3, 1);

function advertisement() {
for (let i = 0; i < vehicleCodes.length; i += 1) {
vehicleCodes[i] = vehicleCodes[i] + "s";
}
let strLast = vehicleCodes[vehicleCodes.length-1];
let arr1 = vehicleCodes.slice(0, [vehicleCodes.length-1]);
let str1 = arr1.toString();
let str2 = str1.replace(/,/g,', ');
console.log(`Amazing Joe's Garage, we service ${str2} and ${strLast}.`);
};
advertisement();
4 changes: 4 additions & 0 deletions Week3/task09MakeObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let Object = {};
Object.teachers = ["Wilgert Velinga", "Bonan Zhao", "Yash Kapila"];
Object.languages = ["Html / Css", "Git", "JavaScript"]
console.log(Object);
Loading