-
-
Notifications
You must be signed in to change notification settings - Fork 382
Birmingham | 26-ITP-May | Toluwalase Tiamiyu | Sprint 1 | Coursework #1380
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
704f58f
dc17501
dce53b5
cecb6ba
bbfef51
274fe16
63265cb
e6db536
1c5023d
b06aae3
496d1b8
32d7119
5e06e8c
7503415
ebaef49
6afaba2
ebbbb71
23af249
ca8a1e2
8977bb2
aa69c9f
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,11 +1,16 @@ | ||
| // 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. | ||
|
|
||
| let firstName = "Creola"; | ||
| let middleName = "Katherine"; | ||
| let lastName = "Johnson"; | ||
|
|
||
| // 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. | ||
|
|
||
| let initials = ``; | ||
| function getInitials() { | ||
| let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; | ||
| return initials; | ||
| } | ||
|
|
||
| // https://www.google.com/search?q=get+first+character+of+string+mdn | ||
| console.log(getInitials()); | ||
|
|
||
| // Export the initials for testing instead of returning at top-level | ||
| module.exports = getInitials; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| const minimum = 1; | ||
| const maximum = 100; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
| for (let i = 0; i < 5; i++) { | ||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
| console.log(num); | ||
| } | ||
|
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 have done a good job of using for loop to log the value of variable
|
||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // Try breaking down the expression and using documentation to explain what it means | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| 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? | ||
|
|
||
| /* To prevent the computer from executing these lines of code, you can comment them out, | ||
| you can use `//` for single-line comments or `/* */` for multi-line comments, like i demonstated above. |
| 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,22 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| //const cardNumber = 4533787178994213; | ||
| //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 wont work because the card number isnt in ("") and the computer wont be able to apply the .slice due to this. | ||
|
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. It is good practice to use single line comment or multiline comment whenever required. try looking for lines which needs to be ignored by computer in the code.
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. I see what you mean and i have commented out the headings i created earlier. |
||
|
|
||
| //THE ERROR: | ||
| //cardNumber.slice is not a function | ||
|
|
||
| //YES! the error is what i predicted. | ||
|
|
||
| //FIX: | ||
| const cardnumber = "4533787178994213"; | ||
| const last4Digits = cardnumber.slice(-4); | ||
| console.log(last4Digits); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| const twentyFourHourClockTime = "20:53"; | ||
|
|
||
| //The Error: | ||
| //The code would not run because only a letter can follow the 'const' and 'let' declarations in javascript. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,26 @@ 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 | ||
| //1. Line 5: carPrice.replaceAll(",", "") | ||
| //2. Line 6: priceAfterOneYear.replaceAll(",", "") | ||
| //3. Line 8: console.log(`The percentage change is ${percentageChange}`) | ||
|
|
||
| // 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? | ||
| //The error is in line 5, the error is occurring because "comma missing "," and "" for priceAfterOneYear.replaceAll("," "") function call. | ||
|
|
||
|
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. Instead of writing comma is missing here, we can put it like "Comma is missing
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. Your suggestion is better and i have incorporated it, thank you. |
||
| // 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? | ||
| //The expression is converting the string representation of the car price to a number by first removing the comma. | ||
|
|
||
| //Purpose: | ||
| //To allow the computer identify the value of the car price as a number so that it can be used in calculations. | ||
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.
Think of ways to use
slicemethod extract and store directory part and extension part in the variabledirandextrespectively.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.
Thank you for your review, i have infused the .slice method and i have used the console.log to recall the answer to 'dir' and 'ext', rather than manually inputting it.