Skip to content

Commit

Permalink
Tugas Quiz Day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
kaysypy committed May 27, 2022
0 parents commit 64a1477
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
23 changes: 23 additions & 0 deletions AngkaPalindrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** input 4 digit, cek apakah angka palindrome */

function isPalindrome(angka){
if(isNaN(angka)){
return angka+" is not an number"
}

else{
if(String(angka) == String(angka).split('').reverse().join('')){
return angka+" is palindrome";
}
else{
return angka+" is not palindrome";
}
}
}


console.log(isPalindrome("abcd"));//abcd is not an number
console.log(isPalindrome("123a"));//123a is not an number
console.log(isPalindrome("1234"));//1234 is not palindrome
console.log(isPalindrome(1221));//1221 is palindrome
console.log(isPalindrome("8888"));//8888 is palindrome
25 changes: 25 additions & 0 deletions AreaCircle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
Diketahui rumus area = pi * radius * radius dimana pi = 3.14159, r = radius buat function dengan nama getAreaCircle(r)
Output Contraint :
getAreaCircle('-1'); //return radius -1 <= 0, try higher
getAreaCircle('a'); //return Inputan harus dalam angka
getAreaCircle(5); //retun 78.53975
*/

function getAreaCircle(r) {
if(r<=0){
return "radius -1 <= 0, try higher"
}

else if(isNaN(r)){
return "Inputan harus dalam angka"
}
else{
return Math.PI.toFixed(5)*Math.pow(r,2);
}
}


console.log(getAreaCircle('-1')); //return radius -1 <= 0, try higher
console.log(getAreaCircle('a')); //return Inputan harus dalam angka
console.log(getAreaCircle(5).toFixed(5)); //retun 78.53975
28 changes: 28 additions & 0 deletions Bill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** hitung total gaji karyawan */

function totalGaji(gaji1, gaji2, gaji3) {
let bayar1=gaji1+(taxGaji(gaji1)*gaji1);
let bayar2=gaji2+(taxGaji(gaji2)*gaji2);
let bayar3=gaji3+(taxGaji(gaji3)*gaji3);
let total=bayar1+bayar2+bayar3;
return "Total gaji yang harus dibayar :\nEmp1 : Rp."+gaji1+" + Pajak("+taxGaji(gaji1)*100+"%)=Rp."+bayar1+"\nEmp2 : Rp."+gaji2+" + Pajak("+taxGaji(gaji2)*100+"%)=Rp."+bayar2+"\nEmp3 : Rp."+gaji3+" + Pajak("+taxGaji(gaji3)*100+"%)=Rp."+bayar3+"\nTotal : Rp."+total;
}

function taxGaji(gaji) {
if (gaji >= 10000) {
return (10 / 100).toFixed(2)
} else if (gaji >= 1000 && gaji < 10000) {
return (5 / 100).toFixed(2)
} else if (gaji >= 100 && gaji < 1000) {
return (2 / 100).toFixed(2)
}
}

console.log(totalGaji(500, 2000, 12000));
/**
Total gaji yang harus dibayar :
Emp1 : Rp.500 + Pajak(2%)=Rp.510
Emp1 : Rp.2000 + Pajak(5%)=Rp.2100
Emp1 : Rp.12000 + Pajak(10%)=Rp.13200
Total : Rp.15810
*/
26 changes: 26 additions & 0 deletions ConvertRupiah.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Convert rupiah to other currency
*/

function convertToRupiah(money,type){
if(type=="yen"){
let result=money*130.12;
return Intl.NumberFormat('ID',{style:'currency',currency:'IDR',maximumFractionDigits: 0, minimumFractionDigits: 0}).format(result)
}
else if(type=="usd"){
let result=money*14382.5;
return Intl.NumberFormat('ID',{style:'currency',currency:'IDR',maximumFractionDigits: 0, minimumFractionDigits: 0}).format(result)
}
else if(type=="euro"){
let result=money*16000;
return Intl.NumberFormat('ID',{style:'currency',currency:'IDR',maximumFractionDigits: 0, minimumFractionDigits: 0}).format(result)
}
else{
return "no match type currency"
}
}

console.log(convertToRupiah(1000,'yen'));//1000 yen = Rp.130.120
console.log(convertToRupiah(100,'usd'));//100 dollar = Rp.1.438.250
console.log(convertToRupiah(100,'euro'));//100 dollar = Rp.1.600.000
console.log(convertToRupiah(100,''));//no match type currency
18 changes: 18 additions & 0 deletions ConvertSuhu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* konversi fareinheit to kelvin
* rumus Kelvin = (Fareinheit + 459.67)/1.8
*
*/

function fareinheitToKelvin(fareinheit){
if(isNaN(fareinheit)){
return "Fareinheit must an number"
}
else{
return "Convert Fareinheit ("+fareinheit+") to Kelvin = "+ ((fareinheit + 459.67)/1.8).toFixed();
}
}

console.log(fareinheitToKelvin(45)); //Convert Fareinheit (45) to Kelvin = 280
console.log(fareinheitToKelvin("1")); //Convert Fareinheit (1) to Kelvin = 811
console.log(fareinheitToKelvin("F")); //Fareinheit must an number
23 changes: 23 additions & 0 deletions DistanceTravel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** hitung jarak antar kota
* dimana rumus jarak S = 1/2*a*t^2
* function calculateDistance(a,t),
* where a = accelaration in number
* t : time
*/

function calculateDistance(a, t){
if(a<=0 || t<=0){
return "Accelaration or time must be >= 0"
}

else if(isNaN(a) || isNaN(t)){
return "input must an number"
}
else{
return "Jarak yang ditempuh adalah "+0.5*a*Math.pow(t,2)+" meter/s";
}
}

console.log(calculateDistance("a","t"));//input must an number
console.log(calculateDistance(-1,9)); //Accelaration or time must be >= 0
console.log(calculateDistance(50,60)); //Jarak yang ditempuh adalah 90000 meter/s
31 changes: 31 additions & 0 deletions ElapsedTimes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* hitung detik ke dalam day, hour, minute and seconds
*/


function getPeriodTimes(seconds) {
if(isNaN(seconds)){
return seconds+" is not number"
}
else{
const secondsInAMinute = 60;
const secondsInAnHour = 60 * secondsInAMinute;
const secondsInADay = 24 * secondsInAnHour;

const days = Math.floor(seconds / secondsInADay);

const hourSeconds = seconds % secondsInADay;
const hours = Math.floor(hourSeconds / secondsInAnHour);

const minuteSeconds = hourSeconds % secondsInAnHour;
const minutes = Math.floor(minuteSeconds / secondsInAMinute);

const remainingSeconds = minuteSeconds % secondsInAMinute;
const second = Math.ceil(remainingSeconds);

return days+" hari "+hours+" jam "+minutes+" menit "+second+" detik";
}
}

console.log(getPeriodTimes("700005A"));//700005A is not number
console.log(getPeriodTimes("700005"));//8 hari 2 jam 26 menit 45 detik
28 changes: 28 additions & 0 deletions GetDays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** Display year is kabisat and display month */

function getDays(month,year){
if(isNaN(month) && !isNaN(year)){
return "inputan bulan harus dalam integer"
}
else if(!isNaN(month) && isNaN(year)){
return "inputan tahun harus dalam integer"
}
else if(isNaN(month) && isNaN(year)){
return "inputan bulan & tahun harus dalam integer"
}
else{
if(year%4==0){
return "This month has "+new Date(year, month, 0).getDate()+" days, "+year+" adalah tahun kabisat";
}
else if(year%4!=0){
return "This month has "+new Date(year, month, 0).getDate()+" days";
}

}
}

console.log(getDays("a",2021)); //inputan bulan harus dalam integer
console.log(getDays("2","year")); //inputan tahun harus dalam integer
console.log(getDays("m","year"));//inputan bulan & tahun harus dalam integer
console.log(getDays(2,2000)); //This month has 29 days, 2000 adalah tahun kabisat
console.log(getDays(8,2021)); //This month has 31 hari
9 changes: 9 additions & 0 deletions HeaviestPerson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* hitung orang yg memiliki berat badan paling tinggi
*/

function getHeavier(w1,wg2,wg3){
return Math.max(w1,wg2,wg3);
}

console.log(getHeavier(12,45,70));//70
18 changes: 18 additions & 0 deletions JarakKordinat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Menghitung jarak kordinat
* 𝑑 = √(𝑥1 − 𝑥2)^2 + (𝑦1 −𝑦2)^2
*/

function getCordinat(x1,y1,x2,y2) {
if(isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)){
return "input kordinat dalam angka";
}
else{
return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
}
}

console.log(getCordinat(3,4,-4,-5)); //9
console.log(getCordinat("1","2","-1","-2")); //1
console.log(getCordinat("x","2","-y","-2")); //input kordinat dalam angka
console.log(getCordinat(3.2,4.5,-4.4,-5)); //13.695801445917125
22 changes: 22 additions & 0 deletions Prosentase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** Buat program untuk menampilkan prosentasi dari income*/

function getProsentase(start,end){
if(isNaN(start) || isNaN(end)){
return start+" or "+end+" harus dalam angka"
}
else{
let increase=((end-start)/start)*100;
if(increase<0){
return "Total penurunan income "+Math.floor(increase)+"%";
}
else{
return "Total kenaikan income "+Math.ceil(increase)+"%";
}

}
}

console.log(getProsentase("abc","bca"));//abc or bca harus dalam angka
console.log(getProsentase(600000.00,750000.00));//Total kenaikan income 25%
console.log(getProsentase(750000.00,650000.00));//Total penurunan income -14%

31 changes: 31 additions & 0 deletions SalesTax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Hitung pajak dari total penjualan
* function getSalesTax(price, tax)
*/

function getSalesTax(price, tax) {
if(isNaN(price) && !isNaN(tax)){
return "Price harus dalam angka"
}
else if(!isNaN(price) && isNaN(tax)){
return "Pajak harus dalam angka"
}
else if(isNaN(price) && isNaN(tax)){
return "Price & Pajak harus dalam angka"
}
else{
let sum=price+tax;
return "Total Sales : Rp."+price+"\nPajak : "+tax+"\nTotalHarga+Pajak : Rp."+sum;
}
}

console.log(getSalesTax("a", 1));//Price harus dalam angka
console.log(getSalesTax(500, "pajak"));//Price & Pajak harus dalam angka
console.log(getSalesTax("harga", "pajak"));//Pajak harus dalam angka
console.log(getSalesTax(4500, 5));
/**
Total Sales : Rp.4500
Pajak : 0.5
TotalHarga+Pajak : Rp.4505
*/
35 changes: 35 additions & 0 deletions SalesTaxRateDiscount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* hitung sales discount plus tax rate
* function getSalesDiscount
*/

function getSalesDiscount(price,tax,discount){
if(isNaN(price) && !isNaN(tax) && !isNaN(discount)){
return "Price harus dalam angka"
}
else if(!isNaN(price) && isNaN(tax) && !isNaN(discount)){
return "Pajak harus dalam angka"
}
else if(isNaN(price) && isNaN(tax) && isNaN(discount)){
return "Price,Pajak & Discount harus dalam angka"
}
else{
let dis=price-(discount/100)*price;
let afterTax=dis/10;
let total=dis+afterTax;
return "Total Sales : Rp."+price+"\nDiscount ("+discount+"%) : Rp."+(discount/100)*price+"\nPriceAfterDiscount : Rp."+dis+"\nPajak ("+tax+"%) : Rp."+afterTax+"\n----------------------------------\nTotalPayment : Rp."+total;
}
}

console.log(getSalesDiscount("a", 1,5));//Price harus dalam angka
console.log(getSalesDiscount(500, "pajak",5));//Pajak harus dalam angka
console.log(getSalesDiscount("harga", "pajak","discount"));//Price, Tax & Discount harus dalam angka
console.log(getSalesDiscount(4500, 10,5));
/**
Total Sales : Rp.4500
Discount (5%) : Rp.225
PriceAfterDiscount : Rp.4275
Pajak (10%) : Rp.427.5
----------------------------------
TotalPayment : Rp.4702.5
*/
20 changes: 20 additions & 0 deletions SumDigits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* input 4 digit integer lalu hitung jumlahnya
*/

function sumDigit(n){
if(n>=10000){
return n+" harus lebih kecil dari 10000"
}
else if(isNaN(n)){
return n+" is not number, try again..."
}
else{
return parseInt(n.toString().charAt(0))+parseInt(n.toString().charAt(1))+parseInt(n.toString().charAt(2))+parseInt(n.toString().charAt(3))
}
}

console.log(sumDigit(1234)); //10
console.log(sumDigit("1234"));//10
console.log(sumDigit(12345));//12345 harus lebih kecil dari 10000
console.log(sumDigit("a123"));//a123 is not number, try again...

0 comments on commit 64a1477

Please sign in to comment.