-
-
Notifications
You must be signed in to change notification settings - Fork 196
Glasgow | ITP-May | Salah Ahmed | Module-Structuring-and-Testing-Data | Sprint-2 #512
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
7c50af2
f0bbd82
ae8a15a
f529c82
d9be0af
936e86f
b45142a
360bd84
50a94d6
9bfd882
8338c01
7b2d300
bfd028e
a307aec
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
"vsliveshare.vsliveshare", | ||
"Orta.vscode-jest" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function checkTime(time){ | ||
|
||
return time.slice(0,1)+time.slice(1,2) | ||
} | ||
|
||
console.log(checkTime("12:34")); // Output: 12 | ||
console.log(checkTime("23:59")); // Output: 23 | ||
|
||
num1 = checkTime("13:34"); | ||
|
||
if (num1 > 12 && num1 < 24) { | ||
|
||
console.log("PM"); | ||
|
||
} else | ||
{ | ||
console.log("AM"); | ||
} |
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,12 @@ | ||
// trying to create an age variable and then reassign the value by 1 | ||
|
||
const age = 33; | ||
age = age + 1; | ||
let age = 33; | ||
age = age + 1; | ||
// The above code will throw an error because 'age' is a constant variable declared with 'const'. | ||
// In JavaScript, variables declared with 'const' cannot be reassigned a new value after their initial assignment. | ||
// To fix this, you can declare 'age' using 'let' instead of 'const', allowing it to be reassigned. | ||
// let age = 33; | ||
console.log(age); // Output: 34 | ||
// The code above declares a variable 'age' with an initial value of 33. | ||
// Then, it reassigns the value of 'age' by adding 1 to its current value. | ||
// The final value of 'age' will be 34, which is the result of the initial value (33) plus 1. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
// 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}`); | ||
//console.log(`I was born in ${cityOfBirth}`); | ||
//const cityOfBirth = "Bolton"; | ||
|
||
// The error occurs because the variable 'cityOfBirth' is being used before it has been declared. | ||
// To fix this, you should declare the variable 'cityOfBirth' before using it in the console.log statement. | ||
// Here's the corrected code: | ||
const cityOfBirth = "Bolton"; | ||
console.log(`I was born in ${cityOfBirth}`); | ||
// Now, the code will correctly print "I was born in Bolton" without any errors. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
const cardNumber = 4533787178994213; | ||
const last4Digits = cardNumber.slice(-4); | ||
//const last4Digits = cardNumber.slice(-4); | ||
|
||
// The last4Digits variable should store the last 4 digits of cardNumber | ||
// However, the code isn't working | ||
// Before running the code, make and explain a prediction about why the code won't work | ||
// 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 | ||
|
||
// Prediction: The code will not work because the `slice` method is being called on a number (cardNumber), which does not have a `slice` method. The `slice` method is typically used with strings or arrays, not numbers. | ||
// Running the code will likely result in a TypeError indicating that `slice` is not a function or is not defined for the number type. | ||
// Running the code confirms the prediction, as it throws an error: "TypeError: cardNumber.slice is not a function". | ||
// To fix this, we need to convert the cardNumber to a string before using the `slice` method. | ||
const last4Digits = String(cardNumber).slice(-4); | ||
// Now, last4Digits will correctly store the last 4 digits of cardNumber. | ||
console.log(`The last 4 digits of the card number are: ${last4Digits}`); | ||
// This will output: "The last 4 digits of the card number are: 4213" | ||
|
||
// The code now works correctly, and the last4Digits variable contains the last four digits of the card number as a string. | ||
// The final output will be "The last 4 digits of the card number are: 4213". |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
const twelveHourClockTime = "20:53"; | ||
const twentyFourHourClockTime = "08:53"; |
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. a) You've correctly identified 2 function calls. How did you decide these were functions? Can you see any others? |
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. b) What is line 10 doing? How would you describe that kind of code? |
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. You correctly identify the effect of |
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. You found that the type of |
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. Can you think of a way to make the fixed function more concise? |
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. Did you do the prediction question first? (Line 4) Can you see a way to change the fixed function to be more concise? |
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.
It's good to see you doing tests to figure things out. Should this testing be included in your pull request?