Skip to content

Format code with prettier and standardjs #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 10 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": [
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
}
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": ["airbnb-base"],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# javascript-programming

> Javascript codes to solve Dicoding quizzes.

- [Content](#Content)
- [Author](#Author)
- [Reference](#Reference)

## Content

- [Variable and Data Type](src/variable-and-data-type)
- [Logic Operator and If Else](src/logic-operator-and-if-else)
- [Object](src/object)
Expand All @@ -18,7 +21,9 @@
- [Concurrency](src/concurrency)

## Author

[Mgs. Tabrani](https://github.com/mgstabrani)

## Reference

[Dicoding](https://www.dicoding.com/)
6 changes: 3 additions & 3 deletions src/array/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
*/

// TODO
const evenNumber = [];
const evenNumber = []
for (let i = 1; i <= 50; i += 1) {
evenNumber.push(i * 2);
evenNumber.push(i * 2)
}

/**
* Hiraukan kode di bawah ini
*/

module.exports = evenNumber;
module.exports = evenNumber
8 changes: 4 additions & 4 deletions src/concurrency/NetworkError.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class NetworkError extends Error {
constructor(message) {
super(message);
this.name = 'NetworkError';
constructor (message) {
super(message)
this.name = 'NetworkError'
}
}

module.exports = NetworkError;
module.exports = NetworkError
37 changes: 19 additions & 18 deletions src/concurrency/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,33 @@
* - Tetap gunakan NetworkError untuk membawa nilai error pada Promise
*/

const NetworkError = require('./NetworkError');
const NetworkError = require('./NetworkError')

// TODO: 1
const fetchingUserFromInternet = (isOffline) => new Promise((resolve, reject) => {
setTimeout(() => {
if (!isOffline) {
resolve({ name: 'John', age: 18 });
} else {
reject(new NetworkError('Gagal mendapatkan data dari internet'), null);
}
}, 500);
});
const fetchingUserFromInternet = (isOffline) =>
new Promise((resolve, reject) => {
setTimeout(() => {
if (!isOffline) {
resolve({ name: 'John', age: 18 })
} else {
reject(new NetworkError('Gagal mendapatkan data dari internet'), null)
}
}, 500)
})

// TODO: 2
async function gettingUserName() {
async function gettingUserName () {
try {
const user = await fetchingUserFromInternet(false);
return user.name;
const user = await fetchingUserFromInternet(false)
return user.name
} catch (rejectedReason) {
return rejectedReason;
return rejectedReason
}
}
gettingUserName();
gettingUserName()

/**
* Hiarukan kode di bawah ini
*/
* Hiarukan kode di bawah ini
*/

module.exports = { fetchingUserFromInternet, gettingUserName };
module.exports = { fetchingUserFromInternet, gettingUserName }
32 changes: 16 additions & 16 deletions src/error-handling/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,46 @@

// TODO 1
class ValidationError extends Error {
constructor(message) {
super(message);
this.name = 'ValidationError';
constructor (message) {
super(message)
this.name = 'ValidationError'
}
}
// TODO 2
function validateNumberInput(a, b, c) {
function validateNumberInput (a, b, c) {
if (typeof a !== 'number') {
throw new ValidationError('Argumen pertama harus number');
throw new ValidationError('Argumen pertama harus number')
}

if (typeof b !== 'number') {
throw new ValidationError('Argumen kedua harus number');
throw new ValidationError('Argumen kedua harus number')
}

if (typeof c !== 'number') {
throw new ValidationError('Argumen ketiga harus number');
throw new ValidationError('Argumen ketiga harus number')
}
}

const detectTriangle = (a, b, c) => {
// TODO 3
try {
validateNumberInput(a, b, c);
validateNumberInput(a, b, c)

if (a === b && b === c) {
return 'Segitiga sama sisi';
return 'Segitiga sama sisi'
}

if (a === b || a === c || b === c) {
return 'Segitiga sama kaki';
return 'Segitiga sama kaki'
}

return 'Segitiga sembarang';
return 'Segitiga sembarang'
} catch (error) {
return error.message;
return error.message
}
};
}

/**
* Hiraukan kode di bawah ini
*/
module.exports = { ValidationError, validateNumberInput, detectTriangle };
* Hiraukan kode di bawah ini
*/
module.exports = { ValidationError, validateNumberInput, detectTriangle }
12 changes: 6 additions & 6 deletions src/function/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
*/

// TODO
function minimal(a, b) {
function minimal (a, b) {
if (b < a) {
return b;
return b
}
return a;
return a
}

function power(a, b) {
return a ** b;
function power (a, b) {
return a ** b
}

/**
* Hiraukan kode di bawah ini
*/

module.exports = { minimal, power };
module.exports = { minimal, power }
19 changes: 13 additions & 6 deletions src/functional-programming/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ const books = [
{ title: 'The Ghost', author: 'Robert Harris', sales: 807311 },
{ title: 'White Teeth', author: 'Zadie Smith', sales: 815586 },
{ title: 'Fifty Shades of Grey', author: 'E. L. James', sales: 3758936 },
{ title: 'Jamie\'s Italy', author: 'Jamie Oliver', sales: 906968 },
{ title: "Jamie's Italy", author: 'Jamie Oliver', sales: 906968 },
{ title: 'I Can Make You Thin', author: 'Paul McKenna', sales: 905086 },
{ title: 'Harry Potter and the Deathly Hallows', author: 'J.K Rowling', sales: 4475152 },
];
{
title: 'Harry Potter and the Deathly Hallows',
author: 'J.K Rowling',
sales: 4475152
}
]

// TODO
let greatAuthors = books.filter((book) => book.sales > 1000000);
greatAuthors = greatAuthors.map((book) => `${book.author} adalah penulis buku ${book.title} yang sangat hebat!`);
let greatAuthors = books.filter((book) => book.sales > 1000000)
greatAuthors = greatAuthors.map(
(book) =>
`${book.author} adalah penulis buku ${book.title} yang sangat hebat!`
)

/**
* Hiraukan kode di bawah ini
*/

module.exports = { books, greatAuthors };
module.exports = { books, greatAuthors }
22 changes: 11 additions & 11 deletions src/logic-operator-and-if-else/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@
*
*/

function scoreChecker(score) {
let result;
function scoreChecker (score) {
let result

// TODO
if (score >= 90) {
result = 'Selamat! Anda mendapatkan nilai A.';
result = 'Selamat! Anda mendapatkan nilai A.'
} else if (score >= 80) {
result = 'Anda mendapatkan nilai B.';
result = 'Anda mendapatkan nilai B.'
} else if (score >= 70) {
result = 'Anda mendapatkan nilai C.';
result = 'Anda mendapatkan nilai C.'
} else if (score >= 60) {
result = 'Anda mendapatkan nilai D.';
result = 'Anda mendapatkan nilai D.'
} else {
result = 'Anda mendapatkan nilai E.';
result = 'Anda mendapatkan nilai E.'
}

// Jangan hapus kode ini
return result;
return result
}

/**
* Hiraukan kode di bawah ini
*/
module.exports = scoreChecker;
* Hiraukan kode di bawah ini
*/
module.exports = scoreChecker
14 changes: 7 additions & 7 deletions src/map/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const currency = new Map([
['USD', 14000],
['JPY', 131],
['SGD', 11000],
['MYR', 3500],
]);
['MYR', 3500]
])

const priceInJPY = 5000;
const priceInIDR = priceInJPY * currency.get('JPY');
const priceInJPY = 5000
const priceInIDR = priceInJPY * currency.get('JPY')
// TODO

/**
* Hiraukan kode di bawah ini
*/
module.exports = { currency, priceInJPY, priceInIDR };
* Hiraukan kode di bawah ini
*/
module.exports = { currency, priceInJPY, priceInIDR }
10 changes: 5 additions & 5 deletions src/module/Tiger.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable class-methods-use-this */
class Tiger {
constructor() {
this.strength = Math.floor(Math.random() * 100);
constructor () {
this.strength = Math.floor(Math.random() * 100)
}

growl() {
return 'grrrrrrr';
growl () {
return 'grrrrrrr'
}
}

// TODO: 1

module.exports = Tiger;
module.exports = Tiger
10 changes: 5 additions & 5 deletions src/module/Wolf.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable class-methods-use-this */
class Wolf {
constructor() {
this.strength = Math.floor(Math.random() * 100);
constructor () {
this.strength = Math.floor(Math.random() * 100)
}

howl() {
return 'Auuuuuuuuu';
howl () {
return 'Auuuuuuuuu'
}
}

// TODO 2
module.exports = Wolf;
module.exports = Wolf
25 changes: 14 additions & 11 deletions src/module/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,28 @@
*/

// TODO 3
const Tiger = require('./Tiger');
const Wolf = require('./Wolf');
const Tiger = require('./Tiger')
const Wolf = require('./Wolf')

const fight = (tiger, wolf) => {
if (tiger.strength > wolf.strength) {
return tiger.growl();
return tiger.growl()
}
if (wolf.strength > tiger.strength) {
return wolf.howl();
return wolf.howl()
}
return 'Harimau dan serigala sama-sama kuat!';
};
return 'Harimau dan serigala sama-sama kuat!'
}

const myTiger = new Tiger();
const myWolf = new Wolf();
const myTiger = new Tiger()
const myWolf = new Wolf()

const result = fight(myTiger, myWolf);
const result = fight(myTiger, myWolf)

// TODO 4
module.exports = {
fight, myTiger, myWolf, result,
};
fight,
myTiger,
myWolf,
result
}
Loading