-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-Sep | Anita Amirhaeri | Sprint 2 | Coursework/sprint 2 #1553
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
2300ec7
77546b4
1e39939
d6958a1
6c5f201
4b1bd0d
424ec1c
18a1da4
418784e
7753eb9
b3a99c0
ab458e3
78097f1
e953ec6
87532a7
87d18e1
77da0b4
8a38be1
6d264c2
2e91aea
b48ce39
f35bfdc
3a5af8c
c2075ba
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? we can put back slash to change it into comments. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
| console.log(age) |
| 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 ? | ||
| // what's the error? | ||
| //ReferenceError: Cannot access 'cityOfBirth' before initialization | ||
|
|
||
| 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,9 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| const last4Digits = String(cardNumber).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 | ||
| // Before running the code, make and explain a prediction about why the code won't work?this function works on string NOT numbers | ||
| // 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
|
Contributor
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. Your fix runs. Now add the error. The prep shows three error names: SyntaxError, TypeError and ReferenceError. Which one was it here? And why did it happen? |
||
| const twentyFourHourClockTime= "20:53"; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,15 +11,28 @@ console.log(result); | |
|
|
||
| // For the piece of code above, read the code and then answer the following questions | ||
|
|
||
| // a) How many variable declarations are there in this program? | ||
| // a) How many variable declarations are there in this program?6 | ||
|
|
||
| // b) How many function calls are there? | ||
| // b) How many function calls are there?1 | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents? | ||
| //8784 % 60=24 | ||
| //The % operator is called the remainder operator. | ||
|
Contributor
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 explains
Contributor
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. Yes, 24 seconds. Good. |
||
| //It gives you the remainder left over after division. | ||
| //we can calculate the number of the left seconds after converting the movie length into whole minutes, 24 seconds left over after converting the movie's total length into whole minutes. | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean?This removes the seconds that don't make up a complete minute. | ||
|
Contributor
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. That is the first half. What does dividing by 60 give you after that?
Contributor
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. Right, 146 minutes. |
||
| //Then it divides that number by 60 to convert the seconds into whole minutes. | ||
| //we have 8784 seconds so | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| //8784 - 24 = 8760 | ||
| //8760 / 60 = 146 it is the total minutes | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable?creates a formatted representation of the movie's length in hours, minutes, and seconds. | ||
| //I can name it the movie duration | ||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| //Works properly for non-negative whole-number seconds; decimals/negative values cause formatting problems | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,15 @@ console.log(`£${pounds}.${pence}`); | |
|
|
||
| // You need to do a step-by-step breakdown of each line in this program | ||
| // Try and describe the purpose / rationale behind each step | ||
| //this function penceString.length-1 removes the last p from string so it values 3 because it contains 4 characters minues 1. | ||
| //penceString.substring(0, 3) and it takes the characters from position 0 up to, but not including, position 3. | ||
| //const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");This uses padStart() to make sure the string has at least 3 characters. | ||
| //const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); | ||
| //This line extracts the pounds part. | ||
|
Contributor
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. Line 27 and line 28 repeat the same code. Keep one. Then keep going. What do lines 14 to 16 give for
Contributor
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. Your pence steps are right now, and £3.99 is correct. Lines 27 and 28 still repeat the same code. Delete line 27. |
||
| //line14:penceString = "399p" | ||
|
|
||
| //paddedPenceNumberString is "399". | ||
| //The substring() takes the last two characters, so:"399" → "99" | ||
| //Then .padEnd(2, "0") checks the string is at least 2 characters long. If it already has 2 characters, like "99", without changing the rest. | ||
| //padEnd(2, "0") adds "0" to the end of the string until it reaches a length of 2 and finally line 18 prints the result which is £3.99 | ||
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
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.
After
Math.floor, the number is from 0 to 99. What does+ minimumdo next? What is the smallestnumcan be, and the biggest?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.
Right, 1 to 100. Good.