From b3459a33717d156a687ec1ef6a8c081af3126107 Mon Sep 17 00:00:00 2001 From: FIRST_NAME LAST_NAME Date: Wed, 30 Oct 2024 14:35:56 +0000 Subject: [PATCH 1/3] solved bugs --- Sprint-1/errors/0.js | 4 ++-- Sprint-1/errors/1.js | 2 +- Sprint-1/errors/2.js | 4 ++-- Sprint-1/errors/3.js | 4 +++- Sprint-1/errors/4.js | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Sprint-1/errors/0.js b/Sprint-1/errors/0.js index cf6c5039f..6a7a7f690 100644 --- a/Sprint-1/errors/0.js +++ b/Sprint-1/errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +// This is just an instruction for the first activity - but it is just for human consumption +// We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file diff --git a/Sprint-1/errors/1.js b/Sprint-1/errors/1.js index 7a43cbea7..031839b47 100644 --- a/Sprint-1/errors/1.js +++ b/Sprint-1/errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; diff --git a/Sprint-1/errors/2.js b/Sprint-1/errors/2.js index e09b89831..c46e98083 100644 --- a/Sprint-1/errors/2.js +++ b/Sprint-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}`); + diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index ec101884d..ec82ca9de 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber @@ -7,3 +7,5 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +console.log(last4Digits); \ No newline at end of file diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 21dad8c5d..21fb7d015 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime = "20:53"; +const hourClockTime = "08:53"; From 7c05420e0bf2441e919133db219874c8d4ed608a Mon Sep 17 00:00:00 2001 From: FIRST_NAME LAST_NAME Date: Tue, 5 Nov 2024 12:50:56 +0000 Subject: [PATCH 2/3] resolved comments --- Sprint-1/exercises/count.js | 9 +++++++++ Sprint-1/exercises/decimal.js | 9 +++++++++ Sprint-1/exercises/initials.js | 4 ++++ Sprint-1/exercises/paths.js | 6 ++++++ Sprint-1/exercises/random.js | 30 ++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index 117bcb2b6..d63932187 100644 --- a/Sprint-1/exercises/count.js +++ b/Sprint-1/exercises/count.js @@ -4,3 +4,12 @@ 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 +console.log(count) + +// Explanation of Line 3 (count = count + 1): +// - Assignment (=): The = operator is used to assign a value to a variable. It takes the value on the right-hand side and stores it in the variable on the left-hand side. + +// - What Happens in Line 3: + +// 1. Right-Hand Side (count + 1): This expression is evaluated first. It takes the current value of count (which is 0 initially) and adds 1 to it. The result of this calculation is 1. +// 2. Assignment: The result (1) is then assigned back to the variable count, updating its value from 0 to 1. diff --git a/Sprint-1/exercises/decimal.js b/Sprint-1/exercises/decimal.js index cc5947ce2..a06a8521e 100644 --- a/Sprint-1/exercises/decimal.js +++ b/Sprint-1/exercises/decimal.js @@ -7,3 +7,12 @@ const num = 56.5678; // 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); // 56 +console.log("Whole Number Part:", wholeNumberPart); + +const decimalPart = num - wholeNumberPart; +console.log("Decimal Part:", decimalPart); + +const roundedNum = Math.round(num); // 57 +console.log("Rounded Number:", roundedNum); \ No newline at end of file diff --git a/Sprint-1/exercises/initials.js b/Sprint-1/exercises/initials.js index 6b80cd137..a8cba32d0 100644 --- a/Sprint-1/exercises/initials.js +++ b/Sprint-1/exercises/initials.js @@ -4,3 +4,7 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. + +let firstCaracter = (firstName[0] + middleName[0] + lastName[0]); + +console.log(firstCaracter) \ No newline at end of file diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index c91cd2ab3..1fc52587b 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -16,3 +16,9 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable +const dir = filePath.slice(0, lastSlashIndex); +console.log(`The dir part of ${filePath} is ${dir}`); + +const lastDotIndex = base.lastIndexOf("."); +const ext = base.slice(lastDotIndex + 1); +console.log(`The ext part of ${filePath} is ${ext}`); \ No newline at end of file diff --git a/Sprint-1/exercises/random.js b/Sprint-1/exercises/random.js index 292f83aab..04e53e09f 100644 --- a/Sprint-1/exercises/random.js +++ b/Sprint-1/exercises/random.js @@ -7,3 +7,33 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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 // Try logging the value of num and running the program several times to build an idea of what the program is doing +console.log(num) + + +// Math.random(): +// Generates a random floating-point number between 0 (inclusive) and 1 (exclusive). This means the result could be anything from 0 up to but not including 1. +// Example: 0.345, 0.876, etc. + +// Math.random() * (maximum - minimum + 1): +// This scales the random number to the desired range. +// maximum - minimum + 1 ensures the range includes all numbers between minimum and maximum, inclusive. +// If maximum is 100 and minimum is 1, this gives 100 - 1 + 1 = 100, so the range is now from 0 to just under 100. +// Example: 0.345 * 100 could give 34.5. + +// Math.floor(): +// Takes the floating-point number from the previous step and rounds it down to the nearest whole number. +// This ensures we get an integer. +// Example: Math.floor(34.5) would result in 34. + + +// + minimum: +// After scaling and flooring, we shift the range to start from minimum instead of 0. +// Adding minimum (1 in this case) ensures the random number falls between minimum and maximum. +// Example: If Math.floor() gave 34, adding 1 results in 35. + +// Result: +// num will be a random integer between 1 (inclusive) and 100 (inclusive). + + + + From fca7c9c4ba607c075d103bcf022bc586ae0de479 Mon Sep 17 00:00:00 2001 From: FIRST_NAME LAST_NAME Date: Tue, 5 Nov 2024 13:01:54 +0000 Subject: [PATCH 3/3] resolved comments --- Sprint-1/errors/2.js | 1 + Sprint-1/errors/3.js | 9 ++++++++- Sprint-1/errors/4.js | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Sprint-1/errors/2.js b/Sprint-1/errors/2.js index c46e98083..4a8114669 100644 --- a/Sprint-1/errors/2.js +++ b/Sprint-1/errors/2.js @@ -3,3 +3,4 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); +//Computer reads code from the line by line, so we need to first define variables and then get console. \ No newline at end of file diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index ec82ca9de..24321bee4 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -8,4 +8,11 @@ const last4Digits = cardNumber.slice(-4); // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value -console.log(last4Digits); \ No newline at end of file +console.log(last4Digits); + +// If cardNumber were a number (not a string), this would raise a TypeError because numbers don't have a slice() method. +// If cardNumber were a number, JavaScript would throw a TypeError because slice() is not a method for numbers. +// Why String Conversion Might Not Always Be Ideal: +// 1-Loss of Numerical Context: After converting to a string, performing arithmetic operations requires converting back to a number. +// 2-Performance Considerations: String manipulation can be less efficient than numerical operations, especially in large-scale data processing. +// 3-Clarity: Maintaining a variable as a number can make the code easier to understand in contexts where numeric operations are expected. ​​ diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 21fb7d015..78c9061ff 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,2 +1,13 @@ -const HourClockTime = "20:53"; -const hourClockTime = "08:53"; +const HourClockTime = "20:53"; // Clearly a 24-hour time +const hourClockTime = "08:53"; // Suggests a 12-hour format (AM/PM context implied) + +// Definition: A system of timekeeping where the day is divided into two 12-hour periods: AM (Ante Meridiem, before noon) and PM (Post Meridiem, after noon). +// Example: 8:53 PM in 12-hour format is written as 08:53 PM. + +// Definition: A system where the day runs from 00:00 (midnight) to 23:59 (one minute before the next midnight), without using AM or PM. +// Example: 20:53 in 24-hour format is 8:53 PM in 12-hour format. +// labels in coding is matters!Why? +// 1. Consistency in Naming: Helps with understanding the flow of data. +// 2. Avoiding Ambiguity: Mislabeling can lead to incorrect assumptions about the data type or its usage. +// 3. Efficient Communication: When collaborating, meaningful labels reduce the need for excessive comments or explanations. +