-
-
Notifications
You must be signed in to change notification settings - Fork 200
Sheffield | 25-ITP-SEP | Jak Rhodes-Smith | Sprint 1 | coursework/sprint-1 #703
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 | ||||
---|---|---|---|---|---|---|
|
@@ -17,7 +17,7 @@ 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 = ; | ||||||
const ext = ; | ||||||
const dir = filePath.slice(1, lastSlashIndex); | ||||||
const ext = base.split(".")[1]; | ||||||
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. Some files could have multiple dots in its name. For example, "filename.tar.gz". 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.
Suggested change
Would this be a better solution? 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. This approach can handle the special case I mentioned, which is good enough for this exercise. |
||||||
|
||||||
// https://www.google.com/search?q=slice+mdn | ||||||
// https://www.google.com/search?q=slice+mdn |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,19 @@ 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 | ||
|
||
// The num variable will evaluate to a random number between the minimum and maximum values | ||
|
||
// Math.random() | ||
// Random decimal number (0 - 1) | ||
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. "Random decimal number (0 - 1)" does not quite indicate if the endpoints 0 and 1 are included . We can also use the concise and precise interval notation to describe a range of values.
|
||
|
||
// (maximum - minimum + 1) | ||
// The size of the range | ||
|
||
// Math.random() * (maximum - minimum + 1) | ||
// Random decimal (0 - 100) | ||
|
||
// Math.floor(...) | ||
// Rounds the result down to a whole number (0 - 99) | ||
|
||
// Adding minimum shifts the range up, so the final result is between the minimum and maximum (1 - 100 inclusive) |
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,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}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const cardNumber = 4533787178994213; | ||
const last4Digits = cardNumber.slice(-4); | ||
const last4Digits = Number(cardNumber.toString().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 | ||
|
||
// .slice() will only work on arrays or strings |
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"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
// 1. initialises a string variable with the value "399p" | ||
const penceString = "399p"; | ||
|
||
// 2. removes the trailing 'p' character | ||
const penceStringWithoutTrailingP = penceString.substring( | ||
0, | ||
penceString.length - 1 | ||
); | ||
|
||
// 3. pads the numeric string with leading zeros so it is at least 3 digits | ||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
|
||
// 4. extracts the pound part by taking all but the last two digits | ||
const pounds = paddedPenceNumberString.substring( | ||
0, | ||
paddedPenceNumberString.length - 2 | ||
); | ||
|
||
// 5. extracts the pence part by taking the last two digits, and pads with trailing zeroes if needed | ||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
Comment on lines
+19
to
22
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. Could we expect this program to work as intended for any valid |
||
|
||
// 6. formats and prints the result as a pounds and pence string | ||
console.log(`£${pounds}.${pence}`); | ||
|
||
// This program takes a string representing a price in pence | ||
|
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.
Operation like
count = count + 1
is very common in programming, and there is a programming term describing such operation.Can you find out what one-word programming term describes the operation on line 3?
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.
Increment