From 53dc8b7477c8d73f8566d69f1970feb98b4d61e3 Mon Sep 17 00:00:00 2001 From: zegcamegon Date: Mon, 29 Dec 2025 11:57:54 +0700 Subject: [PATCH 1/7] sudah pusing 1 dan nanti lanjut lagi 2 --- Loop-Array/countingSheep.js | 7 +++++++ Loop-Array/squareSum.js | 7 +++++++ Loop-String/stringRepeat.js | 5 +++++ Pattern-Printing/segitigaSikuTerbalik.js | 6 ++++++ 4 files changed, 25 insertions(+) diff --git a/Loop-Array/countingSheep.js b/Loop-Array/countingSheep.js index e0ee29a..0c48741 100644 --- a/Loop-Array/countingSheep.js +++ b/Loop-Array/countingSheep.js @@ -4,6 +4,13 @@ function countSheeps(sheep) { // TODO + let jumlah =0; + for (let i = 0; i < sheep.length;i++) { + if (sheep[i] === true) { + jumlah++ + } + } + return jumlah; } console.log(countSheeps([])) //0 diff --git a/Loop-Array/squareSum.js b/Loop-Array/squareSum.js index 9d07259..0ab8c81 100644 --- a/Loop-Array/squareSum.js +++ b/Loop-Array/squareSum.js @@ -4,6 +4,13 @@ function squareSum(numbers){ //code here + let hasil = 0; + for (let i = 0; i < numbers.length; i++) { + if (numbers[i] != 0) { + hasil = hasil + numbers[i] ** 2; + } + } + return hasil; } console.log(squareSum([1,2])); //5 diff --git a/Loop-String/stringRepeat.js b/Loop-String/stringRepeat.js index ca7175f..56ef137 100644 --- a/Loop-String/stringRepeat.js +++ b/Loop-String/stringRepeat.js @@ -4,6 +4,11 @@ function repeatStr (n, s) { //code here + let hasil = ""; + for (let i = 1; i <= n; i++ ) { + hasil = hasil + s; + } + return hasil; } console.log(repeatStr(3, "*")); //*** diff --git a/Pattern-Printing/segitigaSikuTerbalik.js b/Pattern-Printing/segitigaSikuTerbalik.js index 287c2dd..5acedfe 100644 --- a/Pattern-Printing/segitigaSikuTerbalik.js +++ b/Pattern-Printing/segitigaSikuTerbalik.js @@ -2,6 +2,12 @@ function segitigaTerbalik(num) { let pattern = ''; // code here + for (let i = 0; i < 5; i++) { + for (let j = num; j > i;j--){ + pattern = pattern + "*"; + } + pattern = pattern + "\n"; + } return pattern; } From f2ec0ab8c3a43b5a2933a3d5637b8fe03a753d40 Mon Sep 17 00:00:00 2001 From: zegcamegon Date: Tue, 30 Dec 2025 04:49:18 +0700 Subject: [PATCH 2/7] alhamduillah gak terlalu pusing --- Loop-Number/summation.js | 5 +++++ Loop-String/abbrevName.js | 9 +++++++++ Loop-String/noSpace.js | 10 +++++++++- Loop-String/removeChar.js | 14 ++++++++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Loop-Number/summation.js b/Loop-Number/summation.js index 327ab74..734c3c4 100644 --- a/Loop-Number/summation.js +++ b/Loop-Number/summation.js @@ -5,6 +5,11 @@ function summation (num) { // Code here + let hasil = 0; + for (let i = 0; i < num; i ++) { + hasil += num - i; + } + return hasil; } console.log(summation(1)); //1 diff --git a/Loop-String/abbrevName.js b/Loop-String/abbrevName.js index 48124c2..ec0248a 100644 --- a/Loop-String/abbrevName.js +++ b/Loop-String/abbrevName.js @@ -5,6 +5,15 @@ function abbrevName(name){ //code here + output = ""; + for (let i=0; i < name.length; i++){ + if (name[i] == name[0]) { + output+=name[0]; + } else if (name[i] === " "){ + output+="."+name[i+1]; + } + } + return output; } console.log(abbrevName("Sam Harris")); //S.H diff --git a/Loop-String/noSpace.js b/Loop-String/noSpace.js index e62ba23..1d8b0f6 100644 --- a/Loop-String/noSpace.js +++ b/Loop-String/noSpace.js @@ -4,7 +4,15 @@ function noSpace(x){ //code here - + hasil = ""; + for (let i = 0; i < x.length; i++) { + if (x[i] == " ") { + continue; + } else { + hasil+=x[i]; + } + } + return hasil; } console.log(noSpace("8 j 8 mBliB8g imjB8B8 jl B")) //8j8mBliB8gimjB8B8jlB diff --git a/Loop-String/removeChar.js b/Loop-String/removeChar.js index 2c09bed..b8e0a6b 100644 --- a/Loop-String/removeChar.js +++ b/Loop-String/removeChar.js @@ -3,8 +3,18 @@ //source: https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0 function removeChar(str){ - -}; + let hasil = ""; + for (let i = 0; i < str.length; i++) { + if (i == 0) { + continue; + } else if (i == str.length - 1) { + continue; + } else { + hasil+=str[i]; + } + } + return hasil; +} console.log(removeChar('eloquent')); //loquen console.log(removeChar('country')); //ountr From 603dbfd14ffbb1200679ac1e4e7b7c7f49a3a741 Mon Sep 17 00:00:00 2001 From: zegcamegon Date: Wed, 31 Dec 2025 04:34:52 +0700 Subject: [PATCH 3/7] lanjut besok --- Pattern-Printing/papanCatur.js | 21 +++++++++++++++++++++ Pattern-Printing/persegi.js | 6 ++++++ Pattern-Printing/persegiBolong.js | 16 ++++++++++++++++ Pattern-Printing/piramidTerbalik.js | 10 ++++++++++ Pattern-Printing/segitigaSiku.js | 6 ++++++ 5 files changed, 59 insertions(+) diff --git a/Pattern-Printing/papanCatur.js b/Pattern-Printing/papanCatur.js index c90644e..420763e 100644 --- a/Pattern-Printing/papanCatur.js +++ b/Pattern-Printing/papanCatur.js @@ -4,6 +4,27 @@ function papanCatur(num) { let pattern = ''; // code here + for (let i = 1; i <= num; i++) { + if (i % 2 == 1) { + for (let j = 1; j <= num; j++){ + if (j % 2 == 1) { + pattern+="#"; + } else { + pattern+=" "; + } + } + } else { + // harusnya gak error ya karena j dijalankan salah satu + for (let j = 1; j <= num; j++) { + if (j % 2 == 1) { + pattern+=" "; + } else { + pattern+="#"; + } + } + } + pattern+="\n"; + } return pattern; } diff --git a/Pattern-Printing/persegi.js b/Pattern-Printing/persegi.js index 1c28f6d..3a133de 100644 --- a/Pattern-Printing/persegi.js +++ b/Pattern-Printing/persegi.js @@ -2,6 +2,12 @@ function persegi(num) { let pattern = ''; // code here + for (let i = 1; i <= num; i++) { + for (let j = 1; j <= num; j++){ + pattern+="*"; + } + pattern+='\n'; + } return pattern; } diff --git a/Pattern-Printing/persegiBolong.js b/Pattern-Printing/persegiBolong.js index 398fc02..9c14ea1 100644 --- a/Pattern-Printing/persegiBolong.js +++ b/Pattern-Printing/persegiBolong.js @@ -2,6 +2,22 @@ function persegiBolong(num) { let pattern = ''; // code here + for (let i = 1; i <= num;i++) { + if (i == 1 || i==num) { + for (let j = 1;j <= num;j++) { + pattern+="*"; + } + } else { + for (let k = 1; k <= num;k++) { + if (k == 1 || k == num) { + pattern+="*"; + } else { + pattern+=" "; + } + } + } + pattern+="\n" + } return pattern; } diff --git a/Pattern-Printing/piramidTerbalik.js b/Pattern-Printing/piramidTerbalik.js index 8c5677e..771b40a 100644 --- a/Pattern-Printing/piramidTerbalik.js +++ b/Pattern-Printing/piramidTerbalik.js @@ -1,6 +1,16 @@ function piramidaTerbalik(num) { let pattern = ''; // code here + for (let i = 0; i < num ; i++) { + for (let j = 1; j <= num * 2 - i; j++) { + if (j - i <= 1) { + pattern+=" "; + } else { + pattern+="*"; + } + } + pattern+="\n" + } return pattern; } diff --git a/Pattern-Printing/segitigaSiku.js b/Pattern-Printing/segitigaSiku.js index c5cce1e..a357d1a 100644 --- a/Pattern-Printing/segitigaSiku.js +++ b/Pattern-Printing/segitigaSiku.js @@ -2,6 +2,12 @@ function segitigaSiku(num) { let pattern = ''; // code here + for (let i = 1; i <= num; i++) { + for (let j = 0; j < i; j++) { + pattern+="*"; + } + pattern+="\n" + } return pattern; } From c504c1adc99901125b2adb8824ff29567836aa52 Mon Sep 17 00:00:00 2001 From: zegcamegon Date: Wed, 31 Dec 2025 04:35:39 +0700 Subject: [PATCH 4/7] lanjut besok --- Loop-Array/findNeedle.js | 8 ++++++++ Loop-Array/positifSum.js | 8 ++++++++ Loop-Number/summation.js | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Loop-Array/findNeedle.js b/Loop-Array/findNeedle.js index d4c9660..88286d4 100644 --- a/Loop-Array/findNeedle.js +++ b/Loop-Array/findNeedle.js @@ -4,6 +4,14 @@ function findNeedle(haystack) { // your code here + let pocici = 0; + for (let i = 0; i < haystack.length;i++) { + if (haystack[i] === 'needle') { + pocici+=i; + break; + } + } + return `found the needle at position ${pocici}`; } let haystack_1 = ['3', '123124234', undefined, 'needle', 'world', 'hay', 2, '3', true, false]; diff --git a/Loop-Array/positifSum.js b/Loop-Array/positifSum.js index 6483e00..6b0f3cb 100644 --- a/Loop-Array/positifSum.js +++ b/Loop-Array/positifSum.js @@ -4,6 +4,14 @@ function positiveSum(arr) { //code here + hacil_akir = 0; + for (let pariabel = 0; pariabel < arr.length; pariabel++) { + // gabut guys :) + if (arr[pariabel] > 0) { + hacil_akir+=arr[pariabel]; + } + } + return hacil_akir; } console.log(positiveSum([1,2,3,4,5])) //15 diff --git a/Loop-Number/summation.js b/Loop-Number/summation.js index 734c3c4..c8ebee9 100644 --- a/Loop-Number/summation.js +++ b/Loop-Number/summation.js @@ -6,7 +6,7 @@ function summation (num) { // Code here let hasil = 0; - for (let i = 0; i < num; i ++) { + for (let i = 0; i < num; i++) { hasil += num - i; } return hasil; From aafd3d5801bda66cf2fc81e4e1b2be0dbbb935fc Mon Sep 17 00:00:00 2001 From: zegcamegon Date: Fri, 2 Jan 2026 07:09:12 +0700 Subject: [PATCH 5/7] 1% sehari :) --- Pattern-Printing/papanCatur.js | 3 ++- Pattern-Printing/piramid.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Pattern-Printing/papanCatur.js b/Pattern-Printing/papanCatur.js index 420763e..33880db 100644 --- a/Pattern-Printing/papanCatur.js +++ b/Pattern-Printing/papanCatur.js @@ -14,7 +14,8 @@ function papanCatur(num) { } } } else { - // harusnya gak error ya karena j dijalankan salah satu + // harusnya gak error, yaa karena j dijalankan salah satu + // gabut hehe for (let j = 1; j <= num; j++) { if (j % 2 == 1) { pattern+=" "; diff --git a/Pattern-Printing/piramid.js b/Pattern-Printing/piramid.js index afa2b5d..b813f08 100644 --- a/Pattern-Printing/piramid.js +++ b/Pattern-Printing/piramid.js @@ -3,6 +3,16 @@ function piramida(num) { let pattern = ''; // code here + for (let i = num; i >= 0;i--) { + for (let j = 1; j <= num * 2 - 1 - i; j++) { + if (i >= j) { + pattern+=" "; + } else { + pattern+="*"; + } + } + pattern+="\n"; + } return pattern; } From 9f6f92462d11d8dae0d832dfe107653c85318bde Mon Sep 17 00:00:00 2001 From: zegcamegon Date: Sat, 3 Jan 2026 06:10:00 +0700 Subject: [PATCH 6/7] alhamdulillah selesai --- Pattern-Printing/diamond.js | 20 ++++++++++++++++++++ Pattern-Printing/patternX.js | 10 ++++++++++ Pattern-Printing/piramid2.js | 10 ++++++++++ 3 files changed, 40 insertions(+) diff --git a/Pattern-Printing/diamond.js b/Pattern-Printing/diamond.js index a813fb7..2775063 100644 --- a/Pattern-Printing/diamond.js +++ b/Pattern-Printing/diamond.js @@ -1,6 +1,26 @@ function berlian(num) { let pattern = ''; // code here + for (let i = num; i > 0 ;i--) { + for (let q = 1; q <= num * 2 - i ; q++) { + if (q < i){ + pattern+=" "; + } else { + pattern+="*"; + } + } + pattern+="\n"; + } + for (let j = 1; j <= num; j++) { + for (let r = 0; r < num * 2 - j - 1;r++) { + if (r < j ) { + pattern+=" "; + } else { + pattern+="*"; + } + } + pattern+="\n"; + } return pattern; } diff --git a/Pattern-Printing/patternX.js b/Pattern-Printing/patternX.js index b191574..ac6fda3 100644 --- a/Pattern-Printing/patternX.js +++ b/Pattern-Printing/patternX.js @@ -5,6 +5,16 @@ function polaX(num) { let pattern = ''; // code here + for (let i = 1; i <= num; i++) { + for (let j = 1; j <= num; j++) { + if (i === j || i + j === num + 1) { + pattern+="*" + } else { + pattern+=" "; + } + } + pattern+="\n"; + } return pattern; } diff --git a/Pattern-Printing/piramid2.js b/Pattern-Printing/piramid2.js index 14e316d..d1e2738 100644 --- a/Pattern-Printing/piramid2.js +++ b/Pattern-Printing/piramid2.js @@ -3,6 +3,16 @@ function piramida2(num) { let pattern = ''; // code here + for (let i = 1; i <= num; i++) { + for (let j = 1; j <= num; j++) { + if (j <= num - i) { + pattern+=" "; + } else { + pattern+="* "; + } + } + pattern+="\n" + } return pattern; } From 35111126d846582ad95a6c1686663d0170250584 Mon Sep 17 00:00:00 2001 From: zegcamegon Date: Sat, 3 Jan 2026 07:04:35 +0700 Subject: [PATCH 7/7] alhamdulillah basic loop selesai --- Loop-Array/findHighest.js | 9 ++++++++- Loop-Array/findSmallest.js | 8 ++++++++ Loop-Number/centuryYear.js | 6 +++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Loop-Array/findHighest.js b/Loop-Array/findHighest.js index ffb59a5..9ffb4af 100644 --- a/Loop-Array/findHighest.js +++ b/Loop-Array/findHighest.js @@ -4,7 +4,14 @@ function findHighestInt(arr) { //your code here - + for ( let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr.length - 1; j++) { + if (arr[j] < arr[j+1]) { + [arr[j], arr[j+1]] = [arr[j+1], arr[j]]; + } + } + } + return arr; } console.log(findHighestInt([78,56,232,12,8])); //8 diff --git a/Loop-Array/findSmallest.js b/Loop-Array/findSmallest.js index ad42028..eca2ba5 100644 --- a/Loop-Array/findSmallest.js +++ b/Loop-Array/findSmallest.js @@ -4,6 +4,14 @@ function findSmallestInt(arr) { //your code here + for (let pariabel1 = 0; pariabel1 < arr.length; pariabel1++) { //sorry bang gabut hehehe :) + for (let pariabel2 = 0; pariabel2 < arr.length -1; pariabel2++) { + if (arr[pariabel2] > arr[pariabel2 + 1]) { + [arr[pariabel2], arr[pariabel2 + 1]] = [arr[pariabel2 + 1], arr[pariabel2]]; + } + } + } + return arr; } diff --git a/Loop-Number/centuryYear.js b/Loop-Number/centuryYear.js index 296af71..3c26509 100644 --- a/Loop-Number/centuryYear.js +++ b/Loop-Number/centuryYear.js @@ -6,7 +6,11 @@ function century(year) { // Finish this :) - return; + abad = 1; + for (let i = 1; i < year/100; i++) { + abad+=1; + } + return abad; } console.log(century(1705)); //18