From 706ba9f2bb9003a49fadf96665af622107ee0d3b Mon Sep 17 00:00:00 2001 From: Zahra-Khademi Date: Tue, 3 Oct 2023 07:53:26 +0100 Subject: [PATCH 01/12] fixing errors --- week-1/errors/1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-1/errors/1.js b/week-1/errors/1.js index 7a43cbea..e57b2e97 100644 --- a/week-1/errors/1.js +++ b/week-1/errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log(age); From f41404493439e4da7b04d26922f07e0c314e3bce Mon Sep 17 00:00:00 2001 From: Zahra-Khademi Date: Tue, 3 Oct 2023 08:41:44 +0100 Subject: [PATCH 02/12] fixing the city error --- week-1/errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/errors/2.js b/week-1/errors/2.js index e09b8983..2865eb8a 100644 --- a/week-1/errors/2.js +++ b/week-1/errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From ad378c482640db021044dfefc9dafe22af060236 Mon Sep 17 00:00:00 2001 From: Zahra-Khademi Date: Tue, 3 Oct 2023 15:43:16 +0100 Subject: [PATCH 03/12] fixing the cardnumber error --- week-1/errors/3.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-1/errors/3.js b/week-1/errors/3.js index ffa72ca4..6141d0b4 100644 --- a/week-1/errors/3.js +++ b/week-1/errors/3.js @@ -1,7 +1,9 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working // Make and explain a prediction about why the code won't work // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +Slice() method is a part of a string, not a number. CardNumber becomes a string when enclosed in single quotations. \ No newline at end of file From d6430dd0b84d3c57d2b7bf8bd09519eb179be6af Mon Sep 17 00:00:00 2001 From: Zahra-Khademi Date: Tue, 3 Oct 2023 15:55:35 +0100 Subject: [PATCH 04/12] fixing the time error --- week-1/errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-1/errors/4.js b/week-1/errors/4.js index 21dad8c5..a109cadb 100644 --- a/week-1/errors/4.js +++ b/week-1/errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const twelveClockTime = "20:53"; +const twentyFourhourClockTime = "08:53"; \ No newline at end of file From 6fd7031c73bdb0764577f309272cd6675fb7543a Mon Sep 17 00:00:00 2001 From: Zahra-Khademi Date: Tue, 3 Oct 2023 18:09:55 +0100 Subject: [PATCH 05/12] answering the question --- week-1/exercises/count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/exercises/count.js b/week-1/exercises/count.js index 117bcb2b..64300cd2 100644 --- a/week-1/exercises/count.js +++ b/week-1/exercises/count.js @@ -4,3 +4,4 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing += in line 3 implies the new value 1 for count replaces the previous value, which was 0. \ No newline at end of file From b928b638435494a386e588a415dc8f1939874b77 Mon Sep 17 00:00:00 2001 From: Zahra-Khademi Date: Tue, 3 Oct 2023 18:46:16 +0100 Subject: [PATCH 06/12] Doing the tasks --- week-1/exercises/decimal.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/week-1/exercises/decimal.js b/week-1/exercises/decimal.js index c928eb94..cba55deb 100644 --- a/week-1/exercises/decimal.js +++ b/week-1/exercises/decimal.js @@ -7,3 +7,11 @@ const num = 58.4567; // Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) // Log your variables to the console to check your answers + +const wholeNumberPart = Math.floor(num); +const decimalPart = num - wholeNumberPart; +const roundedNum = Math.round(num); + +console.log(wholeNumberPart); +console.log(decimalPart); +console.log(roundedNum); \ No newline at end of file From 031a748da48e760817d379d9fb3d103da1ba73b6 Mon Sep 17 00:00:00 2001 From: Zahra-Khademi Date: Tue, 3 Oct 2023 19:06:55 +0100 Subject: [PATCH 07/12] doing the tasks --- week-1/exercises/initials.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/week-1/exercises/initials.js b/week-1/exercises/initials.js index c8c68ffe..6f504455 100644 --- a/week-1/exercises/initials.js +++ b/week-1/exercises/initials.js @@ -4,3 +4,11 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first 3 characters of each string in upper case // Log the variable in each case + +let firstInitials = firstName.substring(0, 3).toUpperCase(); +let middleInitials = middleName.substring(0, 3).toUpperCase(); +let lastInitials = lastName.substring(0, 3).toUpperCase(); + +let initials = firstInitials + middleInitials + lastInitials; + +console.log(initials); From 0d4ded3979fe0104ad0520f772e1c606cd53f766 Mon Sep 17 00:00:00 2001 From: Zahra Date: Wed, 1 Nov 2023 22:03:30 +0000 Subject: [PATCH 08/12] logging --- bash.exe.stackdump | 39 ++++++++++++++++++++++++++++++++++++++ week-1/exercises/random.js | 2 ++ 2 files changed, 41 insertions(+) create mode 100644 bash.exe.stackdump diff --git a/bash.exe.stackdump b/bash.exe.stackdump new file mode 100644 index 00000000..e1974b0d --- /dev/null +++ b/bash.exe.stackdump @@ -0,0 +1,39 @@ +Stack trace: +Frame Function Args +0007FFFFCD30 00021006118E (0002102A6010, 000210272B51, 000000000059, 0007FFFFB6E0) msys-2.0.dll+0x2118E +0007FFFFCD30 0002100469BA (0007FFFFCD30, 000200000000, 000700000000, 000700000001) msys-2.0.dll+0x69BA +0007FFFFCD30 0002100469F2 (000000000000, 000000000000, 000000000059, 000700000003) msys-2.0.dll+0x69F2 +0007FFFFCD30 000210101C61 (000210177A63, 000800007550, 000000000000, 0002102752E0) msys-2.0.dll+0xC1C61 +0007FFFFCD30 000210101C79 (0002101778B0, 0007FFFFC8F8, 000000000004, 0007FFFFC910) msys-2.0.dll+0xC1C79 +0007FFFFCD30 000210104644 (0007FFFFCD30, 000000000000, 0007FFFFC910, 0002102752E0) msys-2.0.dll+0xC4644 +0007FFFFCD30 000210059095 (0007FFFFCA60, 000000000000, 000000000000, 0000FFFFFFFF) msys-2.0.dll+0x19095 +0007FFFFCD30 000210059865 (000000000002, 000800006F10, 000000000000, 000000030201) msys-2.0.dll+0x19865 +0007FFFFCD30 000210059D77 (00021017DA35, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x19D77 +0007FFFFCD30 00021005A0B6 (000000000000, 0007FFFFCD30, FFFFFFFFFFFFFFC6, 000700000000) msys-2.0.dll+0x1A0B6 +0007FFFFCD30 000210047151 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x7151 +0007FFFFFFF0 000210045C86 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x5C86 +0007FFFFFFF0 000210045D34 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x5D34 +End of stack trace +Loaded modules: +000100400000 bash.exe +7FFE48610000 ntdll.dll +7FFE482D0000 KERNEL32.DLL +7FFE461D0000 KERNELBASE.dll +7FFE46D20000 USER32.dll +7FFE464D0000 win32u.dll +000210040000 msys-2.0.dll +7FFE46670000 GDI32.dll +7FFE46500000 gdi32full.dll +7FFE45E50000 msvcp_win.dll +7FFE460D0000 ucrtbase.dll +7FFE48390000 advapi32.dll +7FFE479A0000 msvcrt.dll +7FFE48230000 sechost.dll +7FFE47AC0000 RPCRT4.dll +7FFE456A0000 CRYPTBASE.DLL +7FFE45FA0000 bcryptPrimitives.dll +7FFE47200000 IMM32.DLL +7FFE2C250000 netapi32.dll +7FFE30150000 SAMCLI.DLL +7FFE40020000 SAMLIB.dll +7FFE45240000 NETUTILS.DLL diff --git a/week-1/exercises/random.js b/week-1/exercises/random.js index 79a4a4d5..eb1ba31b 100644 --- a/week-1/exercises/random.js +++ b/week-1/exercises/random.js @@ -3,6 +3,8 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +console.log(num); + // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated From 72971cad1d4f13035d7365993b6cf29d3c880fa2 Mon Sep 17 00:00:00 2001 From: Zahra Date: Wed, 1 Nov 2023 22:32:35 +0000 Subject: [PATCH 09/12] capitalizing --- bash.exe.stackdump | 2 +- week-1/errors/4.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bash.exe.stackdump b/bash.exe.stackdump index e1974b0d..de032b4f 100644 --- a/bash.exe.stackdump +++ b/bash.exe.stackdump @@ -21,8 +21,8 @@ Loaded modules: 7FFE461D0000 KERNELBASE.dll 7FFE46D20000 USER32.dll 7FFE464D0000 win32u.dll -000210040000 msys-2.0.dll 7FFE46670000 GDI32.dll +000210040000 msys-2.0.dll 7FFE46500000 gdi32full.dll 7FFE45E50000 msvcp_win.dll 7FFE460D0000 ucrtbase.dll diff --git a/week-1/errors/4.js b/week-1/errors/4.js index a109cadb..da9868e6 100644 --- a/week-1/errors/4.js +++ b/week-1/errors/4.js @@ -1,2 +1,2 @@ const twelveClockTime = "20:53"; -const twentyFourhourClockTime = "08:53"; \ No newline at end of file +const twentyFourHourClockTime = "08:53"; \ No newline at end of file From fdb157ef9dbf42495d0732958ab63d98859b760a Mon Sep 17 00:00:00 2001 From: Zahra Date: Thu, 2 Nov 2023 20:29:38 +0000 Subject: [PATCH 10/12] Answers --- week-1/interpret/percentage-change.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/week-1/interpret/percentage-change.js b/week-1/interpret/percentage-change.js index 5de10319..1657004d 100644 --- a/week-1/interpret/percentage-change.js +++ b/week-1/interpret/percentage-change.js @@ -13,10 +13,23 @@ console.log(`The percentage change is ${percentageChange}`); // a) How many function calls are there in this file? Write down all the lines where a function call is made +//There are two function calls: in line 4: carPrice.replaceAll(",", "") and in line 5: priceAfterOneYear.replaceAll(",", "") + // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? // c) Identify all the lines that are variable reassignment statements + +// carPrice = Number(carPrice.replaceAll(" ", "")); +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(" ", "")); +// const priceDifference = carPrice - priceAfterOneYear; +// const percentageChange = (priceDifference / carPrice) * 100; // d) Identify all the lines that are variable declarations +// let carPrice = "10,000"; +// let priceAfterOneYear = "8,543"; + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// Number(carPrice.replaceAll(",", "")) is used to convert the string carPrice, which is in the format "10,000" with a comma, into a numerical value. +// The replaceAll method is used to remove any commas in the string, and then Number is used to convert the cleaned string into a numeric value. In this case, it converts the string "10,000" to the number 10000. From eee2b43e3032a930a71656d0652cd47f8f0b4ab5 Mon Sep 17 00:00:00 2001 From: Zahra Date: Thu, 2 Nov 2023 21:28:34 +0000 Subject: [PATCH 11/12] Answer to questions --- week-1/interpret/time-format.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/week-1/interpret/time-format.js b/week-1/interpret/time-format.js index 92ac9752..aef93322 100644 --- a/week-1/interpret/time-format.js +++ b/week-1/interpret/time-format.js @@ -14,13 +14,20 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +// 7 // b) How many function calls are there? +// There are no function calls. // c) Using documentation, explain what the expression movieLength % 60 represents +// It represents the number of seconds remaining after converting as many full minutes as possible. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// It converts the total movie length from seconds to minutes. // e) What do you think the variable result represents? Can you think of a better name for this variable? +//The variable result represents a formatted time representation of the movieLength in the format hours:minutes:seconds. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// The code is to ensure that the time representation is accurate and follows the "hours:minutes:seconds" format. From b6ec2d6a95d8f8d8cfbe62e87e9cf63e9460315c Mon Sep 17 00:00:00 2001 From: Zahra Date: Thu, 2 Nov 2023 22:49:28 +0000 Subject: [PATCH 12/12] My description --- week-1/interpret/to-pounds.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/week-1/interpret/to-pounds.js b/week-1/interpret/to-pounds.js index 60c9ace6..61cbc0b0 100644 --- a/week-1/interpret/to-pounds.js +++ b/week-1/interpret/to-pounds.js @@ -25,3 +25,10 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +//const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);: Removes the trailing 'p' from the penceString by creating a substring that excludes the last character. The result is stored in the penceStringWithoutTrailingP variable. + +//const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");: Adds leading zeros to the penceStringWithoutTrailingP to ensure it has a total length of 3 characters. This is done using padStart, and the result is stored in the paddedPenceNumberString variable. + +// const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);: Extracts the part of paddedPenceNumberString representing pounds (the first part of the string) by creating a substring, excluding the last two characters. The result is stored in the pounds variable. +