LONDON | GISLAINE_DELLA_BELLA | Module-Structuring-and-Testing-Data | SPRINT 1 - #187
LONDON | GISLAINE_DELLA_BELLA | Module-Structuring-and-Testing-Data | SPRINT 1#187Della-Bella wants to merge 7 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
I left my comments in the code.
Why not also try questions in the files in folder explore?
| // The code isin't work because slice is a method for strings and arrays, but cardNumber is defined as a number. | ||
| // use slice on a number will result in an error. | ||
|
|
||
| const cardNumber = "4533787178994213"; |
There was a problem hiding this comment.
If you were not allowed to modify the original value assigned to cardNumber (that is, keep it as 4533787178994213), How would you modify your code?
There was a problem hiding this comment.
// New solution without modifying the const cardNumber. I converted it to a String and then used the function Slice because Slice can only be used in a string.
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| function cardnumber() { |
There was a problem hiding this comment.
This function is not needed. You can just modify the following statement to assign the result to the last4Digits variable, or introduce another variable if needed.
const last4Digits = cardNumber.slice(-4);
There was a problem hiding this comment.
done, correct it without modify the const CardNumber
| // 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 | ||
|
|
||
| // on line 3 the variable is getting the value of a variable count and adding 1 to it |
There was a problem hiding this comment.
There is a shorter programming term for operation like count = count + 1. You can try feeding the code to ChatGPT to see how else the code can be described. From time to time you may learn new terminology or more concise ways to describe code.
|
|
||
| // 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. | ||
| function initials() { |
There was a problem hiding this comment.
Could also just assign the result to a variable.
There was a problem hiding this comment.
Done/ New solution assigns it in variables:
let firstInitial = firstName.charAt(0);
let middleInitial = middleName.charAt(0);
let lastInitial = lastName.charAt(0);
| And if the number is negative it will round it to nearest = -4.7 = -5 | ||
|
|
||
| Match.random= is a js function that generates random numbers | ||
| between 0 and 1. |
There was a problem hiding this comment.
The phrase "between 0 and 1" alone is not precise enough in program specification because it does not state clearly whether 0 and 1 are included in the range.
Does the random value returned by Math.random() include 0? Does the return value include 1?
After you find out the answer, may I suggest asking ChatGPT how to precisely describe a range of numbers from 0 to 1 that include/exclude 0/1.
There was a problem hiding this comment.
The num function will generate a random number between 0 and 100. Math.random() would include 0 but as we have " + minimum" this will add 1 to the result. so 0 + 1 will never be 0.
| //1,2 7, 8 | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| //it transform a format number price in a number |
There was a problem hiding this comment.
What kind of "transformation"? There are several things happened in this statement. May I suggest ChatGPT?
There was a problem hiding this comment.
This is what chat GTP gave me .. Seen more clear
carPrice.replaceAll(",", ""): This part removes all commas (",") from the carPrice string.
Number(...): This attempts to convert the resulting string (without commas) into a numerical value.
The purpose of this expression is to prepare the carPrice string for numerical calculations.
By removing the commas, it ensures that the string can be correctly interpreted as a number by the Number() function
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| //6 |
There was a problem hiding this comment.
Which 6 function calls are you referring to?
There was a problem hiding this comment.
Correct answer:
0; the code uses variables (movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result) to store values.
It performs calculations using arithmetic operators like % (modulo) and / (division).
It uses string interpolation (${...}) to create the formatted output.
|
|
||
| //6 | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| //divided by 60, it's convert seconds to a time format |
There was a problem hiding this comment.
This description (and also the descriptions in other comments in this file) are not precise enough. Why don't you ask your new friend ChatGPT for some suggestions.
There was a problem hiding this comment.
It is clear now. is used to show the number of remaining seconds after calculating the total number of minutes in the movie.
"The expression movieLength % 60 in JavaScript represents the modulo operation, which calculates the remainder of the division between movieLength and 60.
In simpler terms:
It divides the movieLength (in seconds) by 60 (the number of seconds in a minute).
The result of this division might have a remainder (e.g., if the movie length is not perfectly divisible by 60).
The % operator specifically extracts this remainder.
Purpose in the Code:
In the given code snippet, movieLength % 60 is used to determine the number of remaining seconds after calculating the total number of minutes in the movie. This is crucial for accurately representing the movie's duration in hours, minutes, and seconds.
Example:
If movieLength is 2784 seconds:
2784 / 60 = 46 with a remainder of 24
movieLength % 60 will result in 24, indicating that there are 24 seconds remaining after 46 full minutes.
| 0, | ||
| penceString.length - 1 | ||
| ); | ||
| 0, // extracts a portion of the string here starting from index 0 |
There was a problem hiding this comment.
Seems to have some typo in this comment.
Some of the other comments are not precise enough.
There was a problem hiding this comment.
I understand clearly now asking to chat GTP line by line.
Revised code and explanation in VS
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); | ||
| .substring(paddedPenceNumberString.length - 2) // extracts the last 2 characters from the strin | ||
| .padEnd(2, "0"); //ensures the string is at least 2 characters long |
There was a problem hiding this comment.
Can we expect this program to work as intended even if we deleted .padEnd(2, "0") from the code?
There was a problem hiding this comment.
I asked cha Gtp and it explain me that it would work as I expected because, without .padEnd(2, "0"), the pence value would be displayed as a single digit when it's less than 10.
Ex: "399p" would be incorrectly displayed as "£3.9" instead of the correct "£3.99".
… String then used the function Slice, because Slice can only //be used in a string.
…o a String then used the function Slice, because Slice can only //be used in a string.
|
Hi cjyuan, |
|
Sorry, what should I do here with this conflict? |
|
Ignore the conflict, we do not need to merge. |
|
ok thank you |
Self checklist
[X ] I have committed my files one by one, on purpose, and for a reason
[ X] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
[X ] I have tested my changes
[X ] My changes follow the style guide
[X ] My changes meet the requirements of this task
Hi volunteer,
Here are my exercises from Sprint 1.
I had to ignore my first branch f and restart again as I was making my changes only in one branch and even following what CJ Juan posted on Slack I couldn't merge the last with the new. So here is going again/exercises Sprint 1.
Thank you for taking the time to review them.
Gislaine
Changelist