From 571227a1f1999a5e89e02fec73ee929e1aa235c9 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 10 Nov 2024 18:00:19 +0000 Subject: [PATCH 01/26] doe 0.js --- Sprint-2/errors/0.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index 74640e11..82318dab 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -3,7 +3,34 @@ // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring + /* + we are creating a variable with (let = nameVariable) but the same time we can not assing + the value in the same line. + instead we should call directly the (str = valueAssigned) and with this will Worker. +*/ + + +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } + + + +/*================== fixed =======================*/ + function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } + +console.log(capitalise("alejandra")); + + +/* + In this function we are taking a parameter the string "alejadra" this + entry in the function and assigned in the str = takin the firs character[0].toUpperCase() + and using the function upper... to convert this in capital letter. + but we still need the rest of the string and we use the interpolation to concatenate + the rest calling the string from the position 1 with str.slice(1). +*/ \ No newline at end of file From 716d278cfd2c865d71c41611d7be9645e5848dfb Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 15 Nov 2024 17:52:21 +0000 Subject: [PATCH 02/26] done 0.js --- Sprint-2/debug/0.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/0.js b/Sprint-2/debug/0.js index b46d471a..5c9c4812 100644 --- a/Sprint-2/debug/0.js +++ b/Sprint-2/debug/0.js @@ -1,7 +1,20 @@ // Predict and explain first... +/* + the function won't return anything because we did not have any return so this will be undefine + it will print what is in the console but no in the second console because we are callin the function which will return undefine + + + + function multiply(a, b) { + console.log(a * b); + } +*/ +// ==================== this will return the arguments sent in the second console ==================== + function multiply(a, b) { - console.log(a * b); + return(a * b); } + console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From e307d6b43702577be1a53f139c83cef98576d209 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 15 Nov 2024 19:23:53 +0000 Subject: [PATCH 03/26] done 1.js --- Sprint-2/debug/1.js | 17 ++++++++++++++++- Sprint-2/errors/0.js | 11 ++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index df4020ca..5e4c8285 100644 --- a/Sprint-2/debug/1.js +++ b/Sprint-2/debug/1.js @@ -1,8 +1,23 @@ // Predict and explain first... -function sum(a, b) { +/* + the reason why is returning undefined is because as soon the function find the return + will stop reading the rest. also the addition is ignoring because we have the statement + one line break after the return + + function sum(a, b) { return; a + b; } +*/ + + + +//=================== this will work ============== + +function sum(a, b) { + return a + b; +} + console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index 82318dab..d94e758c 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -1,16 +1,17 @@ // Predict and explain first... // call the function capitalise with a string input -// interpret the error message and figure out why an error is occurring +// interpret the error message and figure out why an error occurring - /* + +/* we are creating a variable with (let = nameVariable) but the same time we can not assing the value in the same line. instead we should call directly the (str = valueAssigned) and with this will Worker. */ -// function capitalise(str) { +// function capitalize(str) { // let str = `${str[0].toUpperCase()}${str.slice(1)}`; // return str; // } @@ -19,12 +20,12 @@ /*================== fixed =======================*/ -function capitalise(str) { +function capitalize(str) { str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -console.log(capitalise("alejandra")); +console.log(capitalize("alejandra")); /* From 71fe9f0c35e77e5d4190bb1f48c74b29b9dd796d Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sat, 16 Nov 2024 12:18:07 +0000 Subject: [PATCH 04/26] done 2.js --- Sprint-2/debug/2.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index bae9652a..8abef4a4 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -1,11 +1,24 @@ // Predict and explain first... +/* +we can not run this function because we settle the variable with const and this won't allow us to reassign +the new value which we are trying to test in the console.log() + const num = 103; function getLastDigit() { return num.toString().slice(-1); } +*/ + +//=========== This will work ============== + +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)}`); From 555b8485aeb2d31dd0ffa46d0a6bb27f1fca1007 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Wed, 27 Nov 2024 15:30:37 +0000 Subject: [PATCH 05/26] done 0.js --- Sprint-2/errors/0.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index d94e758c..ab03bc3f 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -5,9 +5,9 @@ /* - we are creating a variable with (let = nameVariable) but the same time we can not assing + we are creating a variable with (let = nameVariable) but the same time we can not reassign the value in the same line. - instead we should call directly the (str = valueAssigned) and with this will Worker. + instead we should call directly the (str = valueAssigned) and with this will Work */ @@ -30,7 +30,7 @@ console.log(capitalize("alejandra")); /* In this function we are taking a parameter the string "alejadra" this - entry in the function and assigned in the str = takin the firs character[0].toUpperCase() + entry in the function and assigned in the str = taking the firs character[0].toUpperCase() and using the function upper... to convert this in capital letter. but we still need the rest of the string and we use the interpolation to concatenate the rest calling the string from the position 1 with str.slice(1). From 4a48765fd0e6680d3a2d00c38efc9e6155f3c1ff Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Wed, 27 Nov 2024 15:30:46 +0000 Subject: [PATCH 06/26] done 1.js --- Sprint-2/errors/1.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Sprint-2/errors/1.js b/Sprint-2/errors/1.js index 4602ed23..b601ef4f 100644 --- a/Sprint-2/errors/1.js +++ b/Sprint-2/errors/1.js @@ -1,13 +1,35 @@ // Predict and explain first... -// Why will an error occur when this program runs? -// Try playing computer with the example to work out what is going on +/* -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + Why will an error occur when this program runs? + Try playing computer with the example to work out what is going on + + 1. The function won't run because we are not invoking the function, + 2. we have been declared one variable with const and this can not reassigned after, const decimalNumber also has a fixed value + 3. To work efficiently we should assign the parameter =+ inside the function and declare the var decimalNumber + 4. we call the function correctly with its respective argument + + function convertToPercentage(decimalNumber) { + const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; + } + + console.log(decimalNumber); +*/ + + +/*================== fixed =======================*/ + +function convertToPercentage(num) { + const decimalNumber = num; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(convertToPercentage(.2)); //20% + + From f77a0be5a87e9e0f2e18a215412906986751f099 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Wed, 27 Nov 2024 15:30:58 +0000 Subject: [PATCH 07/26] done 2.js --- Sprint-2/errors/2.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Sprint-2/errors/2.js b/Sprint-2/errors/2.js index 814334d9..0953e7ca 100644 --- a/Sprint-2/errors/2.js +++ b/Sprint-2/errors/2.js @@ -3,8 +3,30 @@ // this function should square any number but instead we're going to get an error -function square(3) { + +/* + parameter are in the function, in this example we are not receiving any parameter and this we can not write the + argument directly, + + arguments are in the console.log and we are not calling the function so that's why we are not having any response. + + function square(3) { + return num * num; + + } + +*/ + +/*================== fixed =======================*/ + + +function square(num) { return num * num; } +console.log(square(7)) + + + + From 0f98c63e30108700dd627d3b2e3cd16bf88e2e78 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 19 Dec 2024 18:24:44 +0000 Subject: [PATCH 08/26] done format-time.js --- Sprint-2/extend/format-time.js | 109 +++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 11 deletions(-) diff --git a/Sprint-2/extend/format-time.js b/Sprint-2/extend/format-time.js index f3b83062..2727ee42 100644 --- a/Sprint-2/extend/format-time.js +++ b/Sprint-2/extend/format-time.js @@ -1,24 +1,111 @@ -// This is the latest solution to the problem from the prep. -// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. +/* + This is the latest solution to the problem from the prep. + Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. + + function formatAs12HourClock(time) { + const hours = Number(time.slice(0, 2)); + console.log(hours); + if (hours > 12) { + return `${hours - 12}:00 pm`; + } + return `${time} am`; + } + +*/ + +// ====================== function and cases ======================= + + +// time.slice(0, 2): method that return the positions 0 and 1 of the string, +// const hours = Number(time.slice(0, 2)) will convert the substring in numbes to manipulate and perfoms calculations. + function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + const hours = Number(time.slice(0, 2)); //Extracts characters from position 0 to 2 (not including the character at index 2) + const minutes = time.slice(3, 5); // extract characters from position 3 to 5 (for minutes part) + + if (hours === 0) { + return `12:${minutes} am`; + } else if (hours === 12) { + return `12:${minutes} pm`; + } else if (hours > 12) { + return `${hours - 12}:${minutes} pm`; + } else { + return `${hours}:${minutes} am`; } - return `${time} am`; + //the previous conditions always lead to a return } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; + +// ============================= test =============================== + +const currentOutput = formatAs12HourClock("00:42"); +const targetOutput = "12:42 am"; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` ); -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; + +// ============================= test 1 ============================= + +const currentOutput1 = formatAs12HourClock("00:00"); +const targetOutput1 = "12:00 am"; +console.assert( + currentOutput1 === targetOutput1, + `current output: ${currentOutput1}, target output: ${targetOutput1}` +); + + +// ============================= test 2 failed ====================== + +const currentOutput2 = formatAs12HourClock("26:00"); //26 > 14; go in the second else if, 26-12=14 +const targetOutput2 = "10:00 pm"; + console.assert( currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` + `current output time: ${currentOutput2}, target output: ${targetOutput2}` + //will print Assertion failed: current output time: 14:00 pm, target output: 10:00 pm ); + + + +const testCases = [ + { input: "00:00", expected: "12:00 am" }, + { input: "12:00", expected: "12:00 pm" }, + { input: "15:30", expected: "3:30 pm" }, + { input: "08:05", expected: "8:05 am" }, + { input: "23:59", expected: "11:59 pm" }, +]; + +for (const { input, expected } of testCases) { + const result = formatAs12HourClock(input); + console.assert( + result === expected, + `Input: ${input} | Expected: ${expected}, but got: ${result}` + ); +} + +// ================ icons test with console/log ======================== + +const testCasesIcons = [ + { input: "25:00", expected: "12:00 am" }, //test failed + { input: "12:00", expected: "12:00 pm" }, + { input: "15:30", expected: "3:30 pm" }, + { input: "08:05", expected: "8:05 am" }, + { input: "23:59", expected: "11:59 pm" }, +]; + + +for (const { input, expected } of testCasesIcons) { + const result = formatAs12HourClock(input); + if (result === expected) { + console.log(`✅ Test passed! Input: ${input} | Output: ${result}`); + } else { + console.error( + `❌ Test failed! Input: ${input} | Expected: ${expected}, but got: ${result}` + ); + } +} + + From 6df687f827dc6b6e42372329b254909ab674f7ef Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 19 Dec 2024 23:56:38 +0000 Subject: [PATCH 09/26] done bmi.js --- Sprint-2/implement/bmi.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Sprint-2/implement/bmi.js b/Sprint-2/implement/bmi.js index 259f62d4..17101ace 100644 --- a/Sprint-2/implement/bmi.js +++ b/Sprint-2/implement/bmi.js @@ -13,3 +13,38 @@ // Given someone's weight in kg and height in metres // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place + +// ============================= BMI TEST =============================== + +function bodyMassIndex(weight, height) { + const kilograms = Number(weight); + const metres = Number(height); + + if (kilograms > 0 && metres > 0) { + const bmi = kilograms / metres ** 2; + return Math.round(bmi * 10) / 10; + } + return "Invalid input. Please enter valid weight and height."; +} + + +//Avoid .toFixed() if we need a number (as .toFixed() returns a string). +console.log(bodyMassIndex(70, 0)); + + +/* + Dynamic Precision with Math.round() + Combining Math.pow() with Math.round() offers a dynamic solution for those + seeking a more flexible approach that can adapt to rounding to various decimal + places. + + function roundTo(num, precision) { + const factor = Math.pow(10, precision) + return Math.round(num * factor) / factor + } + console.log(roundTo(4.687, 0)); // Output: 5 + console.log(roundTo(4.687, 1)); //one decimal place + console.log(roundTo(4.687, 2)); //two decimal places + console.log(roundTo(4.687, 3)); // Output: 4.687 + +*/ From 4d95feec0fbf1475c40225ab0a6e1ffbfd3e0d97 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 19 Dec 2024 23:59:11 +0000 Subject: [PATCH 10/26] update format-time.js --- Sprint-2/extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/extend/format-time.js b/Sprint-2/extend/format-time.js index 2727ee42..c3e81cd5 100644 --- a/Sprint-2/extend/format-time.js +++ b/Sprint-2/extend/format-time.js @@ -17,7 +17,7 @@ // time.slice(0, 2): method that return the positions 0 and 1 of the string, -// const hours = Number(time.slice(0, 2)) will convert the substring in numbes to manipulate and perfoms calculations. +// const hours = Number(time.slice(0, 2)) will convert the substring in numbers to manipulate and performs calculations. function formatAs12HourClock(time) { From 5de407c5ddc540dc6771c067cad008b780f42192 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 20 Dec 2024 00:02:58 +0000 Subject: [PATCH 11/26] removed space --- Sprint-2/implement/bmi.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/implement/bmi.js b/Sprint-2/implement/bmi.js index 17101ace..8e8f5d50 100644 --- a/Sprint-2/implement/bmi.js +++ b/Sprint-2/implement/bmi.js @@ -27,7 +27,6 @@ function bodyMassIndex(weight, height) { return "Invalid input. Please enter valid weight and height."; } - //Avoid .toFixed() if we need a number (as .toFixed() returns a string). console.log(bodyMassIndex(70, 0)); From c9f3f147657b87eadd622b575f9c5aad12362e83 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 20 Dec 2024 00:03:02 +0000 Subject: [PATCH 12/26] removed an empty line --- Sprint-2/implement/to-pounds.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index 6265a1a7..cebe8a3e 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -4,3 +4,36 @@ // 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 = "399p"; + +const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 +); + +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 +); + +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + +console.log(`£${pounds}.${pence}`); + +// This program takes a string representing a price in pence +// The program then builds up a string representing the price in pounds + +// You need to do a step-by-step breakdown of each line in this program +// Try and describe the purpose / rationale behind each step + +// To begin, we can start with +// 1. const penceString = "399p": initialises a string variable with the value "399p" + From bf67d4d2928eade1ad0f426a5bdda4dab5b305e1 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 20 Dec 2024 18:30:33 +0000 Subject: [PATCH 13/26] added the code from sprint1 --- Sprint-1/interpret/to-pounds.js | 3 +++ Sprint-2/implement/to-pounds.js | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Sprint-1/interpret/to-pounds.js b/Sprint-1/interpret/to-pounds.js index 60c9ace6..02b6bc35 100644 --- a/Sprint-1/interpret/to-pounds.js +++ b/Sprint-1/interpret/to-pounds.js @@ -25,3 +25,6 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + + + diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index cebe8a3e..745b6aac 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -28,12 +28,5 @@ const pence = paddedPenceNumberString console.log(`£${pounds}.${pence}`); -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" From 055e5782ff73abc39fc348f6c30de630a50bdb89 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 20 Dec 2024 23:50:47 +0000 Subject: [PATCH 14/26] done tp-pounds.js --- Sprint-2/implement/to-pounds.js | 56 +++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index 745b6aac..4d78cf99 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -5,11 +5,10 @@ // You should call this function a number of times to check it works for different inputs +// ============================= code from Sprint-1 =============================== - - -const penceString = "399p"; +const penceString = "399"; const penceStringWithoutTrailingP = penceString.substring( 0, @@ -28,5 +27,56 @@ const pence = paddedPenceNumberString console.log(`£${pounds}.${pence}`); +// ================= Converted as reusable block of code ======================== + +function convertPenceToPounds(priceAmount) { + const numberwithoutpence = priceAmount.substring(0, priceAmount.length - 1); + const paddedPenceNumberString = numberwithoutpence.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + return `£${pounds}.${pence}`; +} + +priceAmount = "999p" + +console.log(convertPenceToPounds(priceAmount)); + + +// ==================== function handling decimal inputs ======================== + +priceAmounts = "5.23p"; + +function convertPenceToPound(priceAmounts) { + const cleanInput = priceAmounts.substring(0, priceAmounts.length - 1); + + if (cleanInput.includes(".")) { + const [pounds, pence] = cleanInput.split("."); //destructuring; + const formattedPence = pence.padEnd(2, "0"); + return `£${pounds}.${formattedPence}`; + } else { + // Handle the integer case (e.g., "399p") + const paddedPenceNumberString = cleanInput.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + return `£${pounds}.${pence}`; + } +} +console.log(convertPenceToPound(priceAmounts)); // "£5.23" +console.log(convertPenceToPound("399p")); // "£3.99" +console.log(convertPenceToPound("3.99p")); // "£3.99" +console.log(convertPenceToPound("50p")); // "£0.50" +console.log(convertPenceToPound("5.5p")); // "£5.50" +console.log(convertPenceToPound("0.3p")); // "£0.30" \ No newline at end of file From 12467cc5b0fe7163a850c66cf912c4779fbb955a Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sat, 21 Dec 2024 12:06:24 +0000 Subject: [PATCH 15/26] done tp-pounds.js --- Sprint-2/implement/vat.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index 3fb16722..a98a585f 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,3 +8,17 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on + + +function addVatporcentage (price) { + const vatIncluded = Number(price * 1.2); //converted the str into number + console.log(typeof vatIncluded); + return `Vat included ${vatIncluded}`; + +} + +console.log(addVatporcentage("30")); + +/* + This will return the new price with the vat included and also converted the string into number with the method Number() +*/ \ No newline at end of file From a40458cf739242bbc48ce26e1e312ac906772825 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sat, 21 Dec 2024 12:16:31 +0000 Subject: [PATCH 16/26] Revert "done tp-pounds.js" This reverts commit 12467cc5b0fe7163a850c66cf912c4779fbb955a. reverted commit --- Sprint-2/implement/vat.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index a98a585f..3fb16722 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,17 +8,3 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on - - -function addVatporcentage (price) { - const vatIncluded = Number(price * 1.2); //converted the str into number - console.log(typeof vatIncluded); - return `Vat included ${vatIncluded}`; - -} - -console.log(addVatporcentage("30")); - -/* - This will return the new price with the vat included and also converted the string into number with the method Number() -*/ \ No newline at end of file From 0a8af1062420647996ed50f89bfe96d56dc3447a Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sat, 21 Dec 2024 12:22:42 +0000 Subject: [PATCH 17/26] done vat.js --- Sprint-2/implement/vat.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index 3fb16722..5fb6015c 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,3 +8,16 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on + + +function addVatporcentage (price) { + const vatIncluded = Number(price * 1.2); //converted the str into number + return `Vat included ${vatIncluded}`; + +} + +console.log(addVatporcentage("30")); + +/* + This will return the new price with the vat included and also converted the string into number with the method Number() +*/ \ No newline at end of file From 120c3f7a11679011f0ab311ac6a1607f38c65940 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 00:18:41 +0000 Subject: [PATCH 18/26] done cases.js --- Sprint-2/implement/cases.js | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Sprint-2/implement/cases.js b/Sprint-2/implement/cases.js index 9e56a27b..31dda7a3 100644 --- a/Sprint-2/implement/cases.js +++ b/Sprint-2/implement/cases.js @@ -13,3 +13,62 @@ // You will need to come up with an appropriate name for the function // Use the string documentation to help you find a solution + + + +// ================== Strings in UpperCase ===================== + +function convertUpperCaseString(str) { + let UPPER_SNAKE_CASE = ""; +// console.log(typeof str); + + for (let i = 0; i < str.length; i++) { + if (str[i] === " ") { + UPPER_SNAKE_CASE += "_"; + } else UPPER_SNAKE_CASE += str[i].toUpperCase();; + } + + return UPPER_SNAKE_CASE; +} + +console.log(convertUpperCaseString("hola there")); + +// ================ First letter capitalized =================== + + +function firstLetterCapitalized1(str) { + let result = ""; + for (let i = 0; i < str.length; i++) { + if (i === 0 || str[i - 1] === " ") { + result += str[i].toUpperCase(); + } else { + result += str[i]; + } + } + return result; +} + +console.log(firstLetterCapitalized1("first letter capitalized")); + + +// ================ Last letter capitalized =================== + +let quote = 'He said, "It\'s a sunny day!"'; + +function lastLetterCapitalized(str) { + let result = ""; + + for (let i = 0; i < str.length; i++) { + if (str[i + 1] === " " || i === str.length - 1) { + result += str[i].toUpperCase(); + } else { + result += str[i]; + } + } + + return result; +} + +console.log(lastLetterCapitalized(`hola there ${quote}`)); + + From c0e52cb91f19d381406edea6c9229fe5dc7c24d5 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 01:38:15 +0000 Subject: [PATCH 19/26] done time-format.js --- Sprint-2/interpret/time-format.js | 34 +++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Sprint-2/interpret/time-format.js b/Sprint-2/interpret/time-format.js index c5a0c161..5a7a276d 100644 --- a/Sprint-2/interpret/time-format.js +++ b/Sprint-2/interpret/time-format.js @@ -1,4 +1,5 @@ function pad(num) { + console.log(num); return num.toString().padStart(2, "0"); } @@ -7,25 +8,32 @@ function formatTimeDisplay(seconds) { const totalMinutes = (seconds - remainingSeconds) / 60; const remainingMinutes = totalMinutes % 60; const totalHours = (totalMinutes - remainingMinutes) / 60; - - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad( - remainingSeconds - )}`; + return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } -// 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 +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 -// Questions +Questions -// a) When formatTimeDisplay is called how many times will pad be called? +a) When formatTimeDisplay is called how many times will pad be called? + - 3 times, pad is called three times, once for each part of the time: hours, minutes, and seconds. -// Call formatTimeDisplay with an input of 61, now answer the following: +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? +b) What is the value assigned to num when pad is called for the first time? + - 0, because the first pad is totalHours and we don't have any hours yet, only minutes -// c) What is the return value of pad is called for the first time? +c) What is the return value of pad is called for the first time? + - "00" and calling formatTimeDisplay(61) = 00:01:01 -// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer +d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer + - In this case, the value of num before it is passed to pad is 1 (the remainder when 61 are divided by 60). -// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer +e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer + - After pad processes 1, it will return the value "01" because it ensures the number is two digits long (by adding a leading zero) +*/ From e2929c210dbc6170a15da1e14b8878052a6fad48 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 17:02:56 +0000 Subject: [PATCH 20/26] update the response on my prediction on 2.js --- Sprint-2/debug/2.js | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index 8abef4a4..2f4ed516 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -1,27 +1,48 @@ // Predict and explain first... /* -we can not run this function because we settle the variable with const and this won't allow us to reassign -the new value which we are trying to test in the console.log() + - If we run this code. nothing will happen because the function is not called. -const num = 103; + -once we invoke the function this will take the number and converted into string to manipulate and take the las digit and return the new string 42 => will return 2. -function getLastDigit() { - return num.toString().slice(-1); + const num = 103; + + function getLastDigit() { + return num.toString().slice(-1); } */ //=========== This will work ============== +// This program should tell the user the last digit of each number. +// Explain why getLastDigit is not working properly - correct the problem + + +const num = 103; function getLastDigit(num) { - return num.toString().slice(-1); + return num.toString().slice(-1); } - +console.log(`The last digit of 42 is ${getLastDigit(num)}`); 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 + + +//=========== finding the middle digit ============== +// Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 +// Value: 2 0 5 5 5 6 4 2 3 2 5 6 9 + +function getMiddleDigit(num) { + const str = num.toString(); + // console.log(str); + + const middleIndex = Math.floor(str.length / 2); // 13/2 = 6.5 math.floor round the number to the nearest integer 6. + // console.log(middleIndex); + + return str[middleIndex]; //we can access to the position 6 which contains the value '4' +} + +console.log(`The middle of 105 is ${getMiddleDigit(2055564232569)}`); From a28e0205d95e060367e897d33c462f912e3c3780 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 17:37:59 +0000 Subject: [PATCH 21/26] updated my prediction on errors, 0.js --- Sprint-2/errors/0.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index ab03bc3f..9fd228dd 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -5,9 +5,10 @@ /* - we are creating a variable with (let = nameVariable) but the same time we can not reassign - the value in the same line. - instead we should call directly the (str = valueAssigned) and with this will Work + - Occur SyntaxError because the var str has been declared in the in the parameter, so to fix this we + just need to assign the new value. and remove the let. + + - Then call the function */ @@ -16,6 +17,8 @@ // return str; // } +// console.log(capitalize("alejandra")); + /*================== fixed =======================*/ @@ -29,9 +32,12 @@ console.log(capitalize("alejandra")); /* - In this function we are taking a parameter the string "alejadra" this - entry in the function and assigned in the str = taking the firs character[0].toUpperCase() - and using the function upper... to convert this in capital letter. - but we still need the rest of the string and we use the interpolation to concatenate - the rest calling the string from the position 1 with str.slice(1). -*/ \ No newline at end of file + In this function, we are taking a string parameter, "alejandra", as input. + Inside the function, we modify the string by capitalizing the first character. + - First, we access the first character of the string using `str[0]` and use the `toUpperCase()` method + to convert it to a capital letter. + - Then, we use `str.slice(1)` to extract the rest of the string, starting from the second character. + - Finally, we combine the capitalized first letter and the rest of the string using a template literal. + + The result is for the input "alejandra", the output is "Alejandra". +*/ From 21765d4f1b54c97ad12d326fcb622e071877ea46 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 19:14:14 +0000 Subject: [PATCH 22/26] Fix bug in line 62 of cases.js that caused incorrect results in certain conditions. --- Sprint-2/implement/cases.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/cases.js b/Sprint-2/implement/cases.js index 31dda7a3..89a70139 100644 --- a/Sprint-2/implement/cases.js +++ b/Sprint-2/implement/cases.js @@ -59,13 +59,14 @@ function lastLetterCapitalized(str) { let result = ""; for (let i = 0; i < str.length; i++) { - if (str[i + 1] === " " || i === str.length - 1) { + if (i === str.length - 1 || str[i + 1] === " " ) { result += str[i].toUpperCase(); - } else { + } else { result += str[i]; } - } + // console.log(`positions ${i}: of str ${str[i]}`); + } return result; } From da212f6ea4b3a70c164fc24d47dca1f9dcf29e3c Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 20:37:00 +0000 Subject: [PATCH 23/26] Fix the variable money on line 56 to iterate with the function --- Sprint-2/implement/to-pounds.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index 4d78cf99..32d9dfc3 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -23,13 +23,16 @@ const pounds = paddedPenceNumberString.substring( const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + .padEnd(2, "0" + +); + console.log(`£${pounds}.${pence}`); // ================= Converted as reusable block of code ======================== -function convertPenceToPounds(priceAmount) { +function convertPenceToPound1(priceAmount) { const numberwithoutpence = priceAmount.substring(0, priceAmount.length - 1); const paddedPenceNumberString = numberwithoutpence.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( @@ -45,15 +48,15 @@ function convertPenceToPounds(priceAmount) { priceAmount = "999p" -console.log(convertPenceToPounds(priceAmount)); +console.log(convertPenceToPound1(priceAmount)); // ==================== function handling decimal inputs ======================== -priceAmounts = "5.23p"; +money = "0.23p"; -function convertPenceToPound(priceAmounts) { - const cleanInput = priceAmounts.substring(0, priceAmounts.length - 1); +function convertPenceToPounds(money) { + const cleanInput = money.substring(0, money.length - 1); if (cleanInput.includes(".")) { const [pounds, pence] = cleanInput.split("."); //destructuring; @@ -74,9 +77,9 @@ function convertPenceToPound(priceAmounts) { } } -console.log(convertPenceToPound(priceAmounts)); // "£5.23" -console.log(convertPenceToPound("399p")); // "£3.99" -console.log(convertPenceToPound("3.99p")); // "£3.99" -console.log(convertPenceToPound("50p")); // "£0.50" -console.log(convertPenceToPound("5.5p")); // "£5.50" -console.log(convertPenceToPound("0.3p")); // "£0.30" \ No newline at end of file +console.log(convertPenceToPounds(money)); // "£0.23" +console.log(convertPenceToPounds("399p")); // "£3.99" +console.log(convertPenceToPounds("3.99p")); // "£3.99" +console.log(convertPenceToPounds("50p")); // "£0.50" +console.log(convertPenceToPounds("65p")); // £0.65 +console.log(convertPenceToPounds("0.3p")); // "£0.30" \ No newline at end of file From 639ccdbaaaaf8c190b7ce49d756fe9a08f4e150e Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 20:41:46 +0000 Subject: [PATCH 24/26] removed line 50 empty space --- Sprint-2/debug/2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index 2f4ed516..2c56219d 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -19,6 +19,7 @@ const num = 103; +num = 24 function getLastDigit(num) { return num.toString().slice(-1); @@ -45,4 +46,4 @@ function getMiddleDigit(num) { return str[middleIndex]; //we can access to the position 6 which contains the value '4' } -console.log(`The middle of 105 is ${getMiddleDigit(2055564232569)}`); +console.log(`The middle of 105 is ${getMiddleDigit(2055564232569)}`) \ No newline at end of file From ed9ed8fc719e785fbb9c86d500e08bbaf0e5b76b Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 20:42:34 +0000 Subject: [PATCH 25/26] addid some format to the comments lines 3 to 13 --- Sprint-2/debug/2.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index 2c56219d..40d10a81 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -1,16 +1,15 @@ // Predict and explain first... /* - - If we run this code. nothing will happen because the function is not called. + - If we run this code. nothing will happen because the function is not called. - -once we invoke the function this will take the number and converted into string to manipulate and take the las digit and return the new string 42 => will return 2. + -once we invoke the function this will take the number and converted into string to manipulate and take the las digit and return the new string 42 => will return 2. - const num = 103; - - function getLastDigit() { - return num.toString().slice(-1); -} + const num = 103; + function getLastDigit() { + return num.toString().slice(-1); + } */ //=========== This will work ============== From 288cac71f4b34da329c122a31c82f26fdbbd656d Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 23 Dec 2024 23:06:31 +0000 Subject: [PATCH 26/26] Removed the the var num because cause and error reasingned another value, Debug/2.js --- Sprint-2/debug/2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index 40d10a81..d121061e 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -18,7 +18,6 @@ const num = 103; -num = 24 function getLastDigit(num) { return num.toString().slice(-1);