-
-
Notifications
You must be signed in to change notification settings - Fork 167
London | Forogh Aghaeiyarijani | Module-Structuring-and-Testing-Data | sprint1| week1 #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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? | ||
// 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? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// 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}`); | ||
|
||
//Computer reads code from the line by line, so we need to first define variables and then get console. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const cardNumber = 4533787178994213; | ||
const cardNumber = "4533787178994213"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exercise asks you to update "the expression last4Digits is assigned to, in order to get the correct value" Can you try doing this? In your code you have changed the data type to a string. Can you think why or when it might not be a good idea to change a number to a string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If cardNumber were a number (not a string), this would raise a TypeError because numbers don't have a slice() method. |
||
const last4Digits = cardNumber.slice(-4); | ||
|
||
// The last4Digits variable should store the last 4 digits of cardNumber | ||
|
@@ -7,3 +7,12 @@ 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); | ||
|
||
// 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try writing in your explanation as well as fixing the code - we are communicating about code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi SallyMcGrath, Thanks for reviewing my code.
Sprint-1/errors/2.js: //Computer reads code from the line by line, so we need to first define variables and then get console.