-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-SEPT | Carol Nassuna | Sprint 2 | Coursework #1577
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,10 +1,14 @@ | ||
| const firstName = "Creola"; | ||
| const middleName = "Katherine"; | ||
| const lastName = "Johnson"; | ||
| // const initial = "initials"; | ||
| // const index = 1; | ||
|
|
||
| // console.log('The ${Initial} ${index} is ${firstName.charAt(index)}'); | ||
| // Declare a variable called initials that stores the first character of each string. | ||
| // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. | ||
|
|
||
| const initials = ``; | ||
| const initials = firstName[0] + middleName[0] + lastName[0]; | ||
| console.log(initials) | ||
|
|
||
| // https://www.google.com/search?q=get+first+character+of+string+mdn |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| 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? | ||
|
|
||
| // I have commented out the lines. The computer removes commented lines from code compilation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,8 @@ | |
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
|
|
||
| console.log(age) | ||
|
|
||
| // The TypeError: Assignment to constant variable implies we are trying to reassign the variable twice. | ||
| // This case, I have used let instead in order to allow the variable to be reused. | ||
|
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 explanation is right. But line 3 still says |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // 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}`); | ||
|
|
||
| // The error is ReferenceError: Cannot access 'cityOfBirth' before initialization | ||
| // Answer: I switched the order by declaring the const first before calling /printing |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,8 @@ 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 | ||
|
|
||
| //Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file | ||
| // Error returned: TypeError: cardNumber.slice is not a function | ||
| // Lesson learnt here; slice method is only available for strings or arrays not numbers | ||
| // So converted the cardNumber into a string first | ||
|
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 notes are right, and it is good that you wrote down your prediction. But line 2 has not changed. So the file still gives How can line 2 turn |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| const twentyFourHourClockTime = "20:53"; | ||
| console.log(twelveHourClockTime); | ||
| console.log(twentyFourHourClockTime); | ||
|
|
||
| // Error - SyntaxError: Invalid or unexpected token | ||
| // lesson learnt - variables cannot start with a number |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ let carPrice = "10,000"; | |
| let priceAfterOneYear = "8,543"; | ||
|
|
||
| carPrice = Number(carPrice.replaceAll(",", "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , "")); | ||
|
|
||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
@@ -12,11 +12,19 @@ console.log(`The percentage change is ${percentageChange}`); | |
| // Read the code and then answer the questions below | ||
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
|
|
||
| // 2 | ||
|
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. Count again. A function call is a name followed by |
||
| //carPrice = Number(carPrice.replaceAll(",", "")); | ||
| //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ",")); | ||
| // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
|
|
||
| //b) error = SyntaxError: missing ) after argument list | ||
|
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. The error message is right, and your fix works. Which line was the error on? Write the line number too. |
||
| // (",", ",")); - added , between quoted values | ||
| // c) Identify all the lines that are variable reassignment statements | ||
|
|
||
| //carPrice = Number(carPrice.replaceAll(",", "")); | ||
| //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ",")); | ||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| //let carPrice = "10,000"; | ||
| //let priceAfterOneYear = "8,543"; | ||
| //const priceDifference = carPrice - priceAfterOneYear; | ||
| //const percentageChange = (priceDifference / carPrice) * 100; | ||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // e) cleans the amount format by removing characters such as , and leaving only number | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,19 @@ 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? | ||
| // 6 variables | ||
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| // 2 | ||
|
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. There is only one here. |
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // It means 60 % remainder of Movie length | ||
|
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.
|
||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // totalMinutes is assigned a value of the result from (movieLength - remainingSeconds) / 60; | ||
|
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 repeats the code. What does it mean? First, |
||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // I think its the total movie length with a timer. Based on research it appears to be template literal variable as it mixes static text with dynamic data. Sorry I don't fully understand this bit yet | ||
|
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. You are right, it is the movie length. It is shown as hours:minutes:seconds, for example |
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| //any number greater than zero returns a valid positive hour, minute or seconds result. Changing the length to 0 returns 0:0:0. Any negative length returns negative values | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`); | |
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| // 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39 | ||
|
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.
|
||
| // 3. const paddedPenceNumberString - ensures the figure is 3 characters to taking us back to 399 | ||
| // 4 const pounds - removes 2 characters from the amount = 3 | ||
| // 5. const pence - adds the amount by 2 characters taking us back to either 39 or 99 | ||
|
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.
|
||
| // 6. console displays the figures in pounds and pence = 3.99 | ||
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.
Your example is a good start: 0.68 gives 69. Now say what
numis in general. Lognumand run the file a few times. What is the smallest value it can be? And the largest?Also explain each part of line 4.
Math.random()gives a decimal from 0 up to 1, but never 1. What does* 100do to it? Then what doesMath.floordo? And+ minimum?