Skip to content
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
1 change: 1 addition & 0 deletions Week1-Welcome-to-Code
Submodule Week1-Welcome-to-Code added at e209cd
12 changes: 12 additions & 0 deletions quiz/part1/soal1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let nama = "",
peran = ""; // Kesatria, Tabib, Penyhir

if (nama === "") {
console.log("Nama harus diisi!");
} else if (peran === "") {
console.log(
"tapi kayaknya kamu jadi bot aja ya, peran yang kamu pilih ga ada"
);
} else {
console.log(`halo ${peran} ${nama} , kamu dapat menyerang dengan senjatamu!`);
}
45 changes: 45 additions & 0 deletions quiz/part1/soal2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let tanggal = 12; // assign nilai variabel tanggal disini! (dengan angka antara 1 - 31)
let bulan = 12; // assign nilai variabel bulan disini! (dengan angka antara 1 - 12)
let tahun = 2001; // assign nilai variabel tahun disini! (dengan angka antara 1900 - 2200)

switch (bulan) {
case 1:
bulan = "Januari";
break;
case 2:
bulan = "Februari";
break;
case 3:
bulan = "Maret";
break;
case 4:
bulan = "April";
break;
case 5:
bulan = "Mei";
break;
case 6:
bulan = "Juni";
break;
case 7:
bulan = "Juli";
break;
case 8:
bulan = "Agustus";
break;
case 9:
bulan = "September";
break;
case 10:
bulan = "Oktober";
break;
case 11:
bulan = "November";
break;
case 12:
bulan = "Desember";
break;
default:
bulan = "Bulan tidak valid";
}
console.log(tanggal + " " + bulan + " " + tahun);
23 changes: 23 additions & 0 deletions quiz/part2/soal1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let word = "JavaScript";
let second = "is";
let third = "awesome";
let fourth = "and";
let fifth = "I";
let sixth = "love";
let seventh = "it!";

console.log(
word +
" " +
second +
" " +
third +
" " +
fourth +
" " +
fifth +
" " +
sixth +
" " +
seventh
);
22 changes: 22 additions & 0 deletions quiz/part2/soal2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let word = "wow JavaScript is so cool";
let exampleFirstWord = word[0] + word[1] + word[2];
let exampleSecondWord =
word[4] +
word[5] +
word[6] +
word[7] +
word[8] +
word[9] +
word[10] +
word[11] +
word[12] +
word[13];
let exampleThirdWord = word[15] + word[16];
let exampleFourthWord = word[18] + word[19];
let exampleFifthWord = word[21] + word[22] + word[23] + word[24];

console.log("First Word: " + exampleFirstWord);
console.log("Second Word: " + exampleSecondWord);
console.log("Third Word: " + exampleThirdWord);
console.log("Fourth Word: " + exampleFourthWord);
console.log("Fifth Word: " + exampleFifthWord);
12 changes: 12 additions & 0 deletions quiz/part2/soal3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let word3 = "wow JavaScript is so cool";
let exampleFirstWord3 = word3.substring(0, 3);
let exampleSecondWord3 = word3.substring(4, 14);
let exampleThirdWord3 = word3.substring(14, 17);
let exampleFourthWord3 = word3.substring(18, 20);
let exampleFifthWord3 = word3.substring(21, 25);

console.log("First Word: " + exampleFirstWord3);
console.log("Second Word: " + exampleSecondWord3);
console.log("Third Word: " + exampleThirdWord3);
console.log("Fourth Word: " + exampleFourthWord3);
console.log("Fifth Word: " + exampleFifthWord3);
28 changes: 28 additions & 0 deletions quiz/part2/soal4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
let word4 = "wow JavaScript is so cool";
let exampleFirstWord4 = word4.substring(0, 3);
let exampleSecondWord4 = word4.substring(4, 14);
let exampleThirdWord4 = word4.substring(15, 17);
let exampleFourthWord4 = word4.substring(18, 20);
let exampleFifthWord4 = word4.substring(21, 25);

let firstWordLength = exampleFirstWord4.length;
let secondWordLength = exampleSecondWord4.length;
let thirdWordLength = exampleThirdWord4.length;
let fourthWordLength = exampleFourthWord4.length;
let fifthWordLength = exampleFifthWord4.length;

console.log(
"First Word: " + exampleFirstWord4 + ", with length: " + firstWordLength
);
console.log(
"Second Word: " + exampleSecondWord4 + ", with length: " + secondWordLength
);
console.log(
"Third Word: " + exampleThirdWord4 + ", with length: " + thirdWordLength
);
console.log(
"Fourth Word: " + exampleFourthWord4 + ", with length: " + fourthWordLength
);
console.log(
"Fifth Word: " + exampleFifthWord4 + ", with length: " + fifthWordLength
);
13 changes: 13 additions & 0 deletions quiz/part3/soal1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
console.log("Looping Pertama dengan WHILE");
let i = 0;
while (i <= 10) {
console.log(i);
i++;
}

console.log("Looping Kedua dengan WHILE");
let a = 10;
while (a >= 0) {
console.log(a);
a--;
}
8 changes: 8 additions & 0 deletions quiz/part3/soal2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
console.log("Looping pertama engan FOR");
for (let i = 0; i <= 10; i++) {
console.log(i);
}
console.log("Looping kedua dengan FOR");
for (let a = 10; a >= 0; a--) {
console.log(a);
}
7 changes: 7 additions & 0 deletions quiz/part3/soal3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for (let i = 1; i <= 100; i++) {
if (i % 2 == 0) {
console.log(i + " bilangan genap");
} else if (i % 2 != 0) {
console.log(i + " bilangan ganjil");
}
}
20 changes: 20 additions & 0 deletions quiz/part3/soal4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
console.log("=== Perulangan Pertambahan 2, cek kelipatan 3 ===");
for (let i = 1; i <= 100; i += 2) {
if (i % 3 === 0) {
console.log(`${i} kelipatan 3`);
}
}

console.log("=== Perulangan Pertambahan 5, cek kelipatan 6 ===");
for (let i = 1; i <= 100; i += 5) {
if (i % 6 === 0) {
console.log(`${i} kelipatan 6`);
}
}

console.log("=== Perulangan Pertambahan 9, cek kelipatan 10 ===");
for (let i = 1; i <= 100; i += 9) {
if (i % 10 === 0) {
console.log(`${i} kelipatan 10`);
}
}
9 changes: 9 additions & 0 deletions quiz/part3/soal5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// looping bintang
console.log("Looping bintang FOR");
for (let i = 1; i <= 6; i++) {
let bintang = "";
for (let j = 1; j <= i; j++) {
bintang += "*";
}
console.log(bintang);
}
4 changes: 4 additions & 0 deletions quiz/part4/soal1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function shoutOut() {
return "Hello Function!";
}
console.log(shoutOut());
8 changes: 8 additions & 0 deletions quiz/part4/soal2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function calculateMultiply(num1, num2) {
return num1 * num2;
}
let num1 = 1;
let num2 = 2;

let hasilPerkalian = calculateMultiply(num1, num2);
console.log(hasilPerkalian);
11 changes: 11 additions & 0 deletions quiz/part4/soal3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function processSentence(name, age, address, hobby) {
return `Nama saya ${name}, umur saya ${age} tahun, alamat saya di ${address}, dan saya punya hobby yaitu ${hobby}`;
}

let name = "Agus";
let age = 30;
let address = "Jln. Malioboro, Yogjakarta";
let hobby = "gaming";

let fullSentence = processSentence(name, age, address, hobby);
console.log(fullSentence);
11 changes: 11 additions & 0 deletions quiz/ujian/soal1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function bandingkanAngka(angka1, angka2) {
//code disini
return angka1 < angka2 ? true : angka1 > angka2 ? false : -1;
}

// TEST CASES
console.log(bandingkanAngka(5, 8)); // true
console.log(bandingkanAngka(5, 3)); // false
console.log(bandingkanAngka(4, 4)); // -1
console.log(bandingkanAngka(3, 3)); // -1
console.log(bandingkanAngka(17, 2)); // false
11 changes: 11 additions & 0 deletions quiz/ujian/soal2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function balikKata(kata) {
// Reverse the string by splitting, reversing, and joining
return kata.split("").reverse().join("");
}

// TEST CASES
console.log(balikKata("Hello World and Coders")); // sredoC dna dlroW olleH
console.log(balikKata("John Doe")); // eoD nhoJ
console.log(balikKata("I am a bookworm")); // mrowkoob a ma I
console.log(balikKata("Coding is my hobby")); // ybboh ym si gnidoC
console.log(balikKata("Super")); // repuS
13 changes: 13 additions & 0 deletions quiz/ujian/soal3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function konversiMenit(menit) {
// you can only write your code here!
var jam = Math.floor(menit / 60);
var sisaMenit = menit % 60;
return jam + ":" + (sisaMenit < 10 ? "0" + sisaMenit : sisaMenit);
}

// TEST CASES
console.log(konversiMenit(63)); // 1:03
console.log(konversiMenit(124)); // 2:04
console.log(konversiMenit(53)); // 0:53
console.log(konversiMenit(88)); // 1:28
console.log(konversiMenit(120)); // 2:00
24 changes: 24 additions & 0 deletions quiz/ujian/soal4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Problem
// Diberikan sebuah function xo(str) yang menerima satu parameter berupa string.
// Function akan me-return true jika jumlah karakter x sama dengan jumlah karakter o, dan false jika tidak.

function xo(str) {
// you can only write your code here!
var countX = 0;
var countO = 0;
for (var i = 0; i < str.length; i++) {
if (str[i] === "x") {
countX++;
} else if (str[i] === "o") {
countO++;
}
}
return countX === countO;
}

// TEST CASES
console.log(xo("xoxoxo")); // true
console.log(xo("oxooxo")); // false
console.log(xo("oxo")); // false
console.log(xo("xxxooo")); // true
console.log(xo("xoxooxxo")); // true