-
-
Notifications
You must be signed in to change notification settings - Fork 391
London | 26-ITP-May | Mandip sanger | Sprint 1 | Coursework #1516
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
29b8f8d
faa06ac
89a2103
3c3188f
61147c7
6b062a6
103bc69
5d11b8f
7cd725a
79e1444
6fca6cb
1cd3d6d
5775809
1bf7cd3
0664359
23f3931
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,7 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
| // const age = 33; | ||
| // age = age + 1; | ||
|
|
||
| let age = 33; | ||
| age = age + 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
| const cityOfBirth = "Bolton"; | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
|
|
||
| // return has not been defined before it is used in the console.log statement. | ||
| // To fix this, you should declare and assign a value to the variable cityOfBirth before using it in the console.log statement. | ||
| // To do this, you can move the line const cityOfBirth = "Bolton"; above the console.log statement. | ||
| // This way, the variable will be defined before it is used, and the code will work as expected. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(last4Digits); | ||
|
|
||
| // 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 | ||
| // returns an error because the slice method is not available for numbers. The slice method is a string method, and cardNumber is a number. | ||
| // To fix this, we need to convert cardNumber to a string before using the slice method. We can do this by using the toString() method or by using template literals. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,9 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| const twentyFourHourClockTime = "20:53"; | ||
|
|
||
| // 12 Hour clock time is a string that represents the time in 12-hour format, while 24hourClockTime is a string that represents the time in 24-hour format. | ||
| // To convert 12HourClockTime to 24-hour format, we can use the following steps: | ||
| // 1. Split the string into hours and minutes using the split() method. | ||
| // 2. Check if the time is in the "pm" period. If it is, add 12 to the hours (unless it's 12pm). | ||
| // 3. If the time is in the "am" period and the hour is 12, set the hour to 0. | ||
| // 4. Format the hours and minutes into a string in 24-hour format. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,17 @@ const pence = paddedPenceNumberString | |
|
|
||
| console.log(`£${pounds}.${pence}`); | ||
|
|
||
| // This program takes a string representing a price in pence | ||
| // This program takes a string representindng a price in pence | ||
| // The program then builds up a string representing the price in pounds | ||
|
|
||
| // You need to do a step-by-step breakdown of each line in this program | ||
| // Try and describe the purpose / rationale behind each step | ||
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| // const penceString = "399p": initialises a string variable with the value "399p" | ||
|
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. Good start, but please play around with the code and try explaining the rationale behind each step. For example, why is padding needed here?
Author
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. Thank you I will look into these again
Author
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. Padding is used to make sure the number has the correct number of digits before it is split into pounds and pence.padStart(3, "0") adds zeros to the beginning of the string until it is at least 3 characters long. |
||
| // 1. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): creates a new string variable that removes the last character "p" from the original string | ||
| // 2. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): creates a new string variable that pads the original string with leading zeros to make it 3 characters long | ||
| // 3. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion of the string by taking all characters except the last two | ||
| // 4. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence portion of the string by taking the last two characters and pads it with trailing zeros to make it 2 characters long | ||
| // 5. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence to the console | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
please review this code again, you need to fix the error in the file.