From a673f002b692ff42b0f5f3df42d02b5e2edf38a6 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:06:28 +0100 Subject: [PATCH 01/13] solve and comment sprint-2/1-key-errors/0.js --- Sprint-2/1-key-errors/0.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..e10d77121 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,21 @@ // Predict and explain first... // =============> write your prediction here +//the function will turn the first given string into Uppercase. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; + let strWithUpperCase = `${str[0].toUpperCase()}${str.slice(1)}`; + return strWithUpperCase; } // =============> write your explanation here +// str[0].toUpperCase() ---> gets the first character and uses build-in method to convert a char to uppercase +// str.slice(1) ----> will slice the array or sting "start from 1" to the rest of array or string +// we get an error because we "re-declare" the str variable as parameter and as call back of expression + // =============> write your new code here + +const myStr = "i forgot add this string"; +console.log(capitalise(myStr)); From 95d7600a7c3bd6cc4744c68538760ffab745cd4e Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:14:06 +0100 Subject: [PATCH 02/13] solve and comment sprint-2/1-key-errors/1.js --- Sprint-2/1-key-errors/1.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..2c8bbbd2d 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,33 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// decimalNumber variable was declared twice. First as parameter and second as const in function body +// use different variable name, either in parameter or the one in function body. +// any way this function always return the same value because the variable is constant and define inside th function, +// usually a function take a variable from function parameters. +// console.log() will fail to print because no parameter define first. // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); // =============> write your explanation here // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + //-----> should be place as parameter and not as a constant ,,,,,const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +decimalNumber = 0.27; +console.log(convertToPercentage(decimalNumber)); From 089cd0ae35d4f84bbdced893c14857e032f6af53 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:17:18 +0100 Subject: [PATCH 03/13] solve and comment sprint2/1-key-errors/2.js --- Sprint-2/1-key-errors/2.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..cab86aaf8 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,27 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +//the function will return square for every given number. -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here +// ans: Unexpected number // =============> explain this error message here - +// ans: function need num to be defined, instead parameter was given 3 as literal value that does not point to any variable as parameter // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} + +mynum = 3; //define the num +console.log(square(mynum)); //verify the result From c18750b90bbcabffe579cf112ef74e26e56de2c1 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:19:19 +0100 Subject: [PATCH 04/13] solve and comment sprint2/2-mandatory-debug/0.js --- Sprint-2/2-mandatory-debug/0.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..cae15f4e6 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// function will return with result of multiplication of given parameters (i,e: a times b) +// function multiply(a, b) { +// console.log(a * b); +// } -function multiply(a, b) { - console.log(a * b); -} - -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here - +// the function does not return any thing, so as result ${multiply(10, 32)} --> will return as "undefined" // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From e2890318320c735ff786d430013dc6c46e84e542 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:21:06 +0100 Subject: [PATCH 05/13] solve and comment sprint2/2-mandatory-debug/1.js --- Sprint-2/2-mandatory-debug/1.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..71133ca6f 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,23 @@ // Predict and explain first... // =============> write your prediction here +// sure this function wont work because, hang on.. I should predict and pretend that everything is fine +// the function will return with summary of given parameters and console.log will verify it -function sum(a, b) { - return; - a + b; -} +// function sum(a, b) { +// return; +// a + b; +// } -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +//function will execute line the code and escape from the function block whenever it "sees" return.. it will return with any expression put on it +// in this function a+b which is expected as the result is placed after return line because return has ";" so i wont bother look the next line. +// just remove the semicolon next to the return.. and put a+b instead, because some how "prettier" as trusty worthy formatter for this course will always add extra ; for every logical expression (somehow).. :) xixixixi // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); From 743e9a8c1a63d3dbb19a66875bd5853f99c03de8 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:23:05 +0100 Subject: [PATCH 06/13] solve and comment sprint-2/2-mandatory-debug/2.js --- Sprint-2/2-mandatory-debug/2.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..df9a69b35 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,42 @@ // Predict the output of the following code: // =============> Write your prediction here +// alright! from the sake of the function name, I can predict that it will successfully get the last digit +// oh hang-on, where is the parameter???? this programmer must be tired or "coding while eating"... careful aye.. holiday is coming. -const num = 103; +// const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +// function getLastDigit() { +// return num.toString().slice(-1); +// } -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); +// console.log(`The last digit of 42 is ${getLastDigit(42)}`); +// console.log(`The last digit of 105 is ${getLastDigit(105)}`); +// console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Now run the code and compare the output to your prediction // =============> write the output here +// nope.. It runs as predicted :) xixixiixi... that way we are in this "debugging" session. +// it runs but no syntax error but the output are not correct. + // Explain why the output is the way it is // =============> write your explanation here +// the function does not get any "define parameter", like nothing, so it tries to the "num" in global variable +// that is given just before the function that is const num = 103; +// so, every time that function is called, it will use num 103 as parameter + // Finally, correct the code to fix the problem // =============> write your new code here +const num = 103; + +function getLastDigit(num) { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// no syntax error just logic error :) because, sometime we need to manipulate the function just like that. BTW that is not save anyway. From 60dd470cfbdff1de3fbcf19b93fe4789b9f38ed1 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:45:29 +0100 Subject: [PATCH 07/13] solve and comment sprint2/3-mandatory-implement/1-bmi.js --- Sprint-2/3-mandatory-implement/1-bmi.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..7e03d5887 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,17 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + // squaring your height: 1.73 x 1.73 = 2.99 + let heightSquared = height * height; + // dividing 70 by 2.99 = 23.41 + let weightMod = weight / heightSquared; + // Your result will be displayed to 1 decimal place, for example 23.4. + let BMI = weightMod.toFixed(1); + // return the BMI of someone based off their weight and height + return BMI; +} + +let myWeight = 70; +let myHeight = 1.73; + +console.log(`my BMI is ${calculateBMI(myWeight, myHeight)}`); From c26acb4a3f5a3997d9b305012fdab25d05420156 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:47:29 +0100 Subject: [PATCH 08/13] solve and comment sprint-2/3-mandatory-implement/2-cases.js --- Sprint-2/3-mandatory-implement/2-cases.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..bc290d6e0 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,17 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +let myStr = "hello world I am sleepy"; + +// let myStrUpperCase = myStr.toUpperCase(); + +// let arrWord = myStrUpperCase.split(" "); + +// let myStrUpperCaseWithSnakeCase = arrWord.join("_"); + +//console.log(`${arrWord}`); + +let combine = myStr.toUpperCase().split(" ").join("_"); + +console.log(`${combine}`); From 7966e09117c377ece11c8af20a2190795ccfdc6e Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 22:49:55 +0100 Subject: [PATCH 09/13] solve and commit sprint-2/3-mandatory-implement/3-to-pounds.js --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..781aacc33 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,66 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + +//============================================================= +// const penceString = "9p"; //init variable + +// const penceStringWithoutTrailingP = penceString.substring( +// 0, +// penceString.length - 1 +// ); //remove p character at the end of the variable +// console.log(penceStringWithoutTrailingP); + +// const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // +// console.log(paddedPenceNumberString); //give format of 3 zeroes if the number is less than 3 digits. + +// const pounds = paddedPenceNumberString.substring( +// 0, +// paddedPenceNumberString.length - 2 +// ); //get ponds value conversion changes for given pence + +// console.log(pounds); + +// const pence = paddedPenceNumberString +// .substring(paddedPenceNumberString.length - 2) +// .padEnd(2, "0"); //get the reminds after conversion to pounds + +// console.log(`£${pounds}.${pence}`); + +//------------------------------------------------------------------------------------------ + +function pensToPounds(penceString) { + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); //remove p character at the end of the variable + //console.log(penceStringWithoutTrailingP); + + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // + //console.log(paddedPenceNumberString); //give format of 3 zeroes if the number is less than 3 digits. + + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); //get ponds value conversion changes for given pence + + //console.log(pounds); + + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); //get the reminds after conversion to pounds + + return `£${pounds}.${pence}`; +} + +//test----1 +let moneyA = "90p"; +console.log(`${pensToPounds(moneyA)}`); + +//test----2 +moneyA = "710p"; +console.log(`${pensToPounds(moneyA)}`); + +//test----3 +moneyA = "1210p"; +console.log(`${pensToPounds(moneyA)}`); From 83d8bc9c2695de0613672564603cac8de14a46ce Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Mon, 7 Jul 2025 23:46:21 +0100 Subject: [PATCH 10/13] comment Sprint-2/4-mandatory-interpret/time-format.js --- Sprint-2/4-mandatory-interpret/time-format.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..326b3cc90 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,6 +11,9 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +let mySeconds = 61; +console.log(`${formatTimeDisplay(61)}`); + // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions @@ -18,17 +21,18 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here - +//ans: 3 times. // Call formatTimeDisplay with an input of 61, now answer the following: // b) What is the value assigned to num when pad is called for the first time? // =============> write your answer here - +//ans: So, the value assigned to num when pad is called for the first time is 0. // c) What is the return value of pad is called for the first time? // =============> write your answer here - +//ans: 0 // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // =============> write your answer here - +//ans: The last call to pad is pad(remainingSeconds). Therefore, when pad is called for the last time, the value assigned to num is 1. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer // =============> write your answer here +//ans: 01....the return value assigned to num when pad is called for the last time in this program is "01". From 8b56abf8d3b70276b5abe24efa8bda4b7e3769f0 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Tue, 8 Jul 2025 00:33:23 +0100 Subject: [PATCH 11/13] solve Sprint-2/5-stretch-extend/format-time.js --- Sprint-2/5-stretch-extend/format-time.js | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..b8194d496 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,7 +4,12 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); - if (hours > 12) { + if (time === "00:00" || time === "24:00") { + //put the edge case on the first checking if-else-case + return `12:00 am`; + } else if (time === "12:00") { + return `12:00 pm`; + } else if (hours > 12) { return `${hours - 12}:00 pm`; } return `${time} am`; @@ -23,3 +28,24 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("00:00"); +const targetOutput3 = "12:00 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("24:00"); +const targetOutput4 = "12:00 am"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("12:00"); +const targetOutput5 = "12:00 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); From d30acb60f222d280c51540f559c3ba824080d275 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Wed, 16 Jul 2025 23:14:46 +0100 Subject: [PATCH 12/13] update --- Sprint-2/1-key-errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index cab86aaf8..216a501ed 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,5 +1,5 @@ // Predict and explain first BEFORE you run any code... - +//>>>>>sure, it // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here From 6a4f2b85a74408b871be6da9858d97ac6b5071f8 Mon Sep 17 00:00:00 2001 From: PandiSimatupang Date: Wed, 16 Jul 2025 23:56:34 +0100 Subject: [PATCH 13/13] change string to character Sprint-2/1-key-errors/0.js --- Sprint-2/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index e10d77121..9423ab450 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -//the function will turn the first given string into Uppercase. +//the function will turn the first given character into Uppercase. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring