Repository navigation
Manchester | 26-ITP-Sep | Mathew Shaibu | Sprint 2 | Course-work-2 #1546
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 55 commits
919f2bc
f93c281
9f085a5
0194cb3
6c5a8c8
b1dcb1c
aed6985
dd027fa
3e2a1d2
b1660fd
ed261ff
5031f8f
ddc8ba6
8c577d5
e44ee66
48b94e2
509ff84
f80c15b
7d0d970
5b4ed9d
c41aa67
08af9b8
536761c
276f457
4aa0e25
4cc01f5
0a50eb5
ae41a8e
a896a16
b5bda05
aedbcb2
655c50e
276400a
c778acb
69717b1
9edf1ff
dba1c5e
d8c4077
90cadba
903b731
3be5165
aade124
239699e
3b45f5d
91b22a2
5b60bb1
d10542b
4793a56
51e9adc
bc34e0e
79db8a6
fb93c79
fb14e2c
5839e8d
973eda4
e29ee81
a675566
9cbdc83
a6c7eb1
ca8e18f
3c63ee6
a5df0de
31c3d98
f214a57
8655d17
b593f3e
92a5450
8dfc043
b33d620
9763a7b
6f10c4b
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,6 +1,6 @@ | ||
| let count = 0; | ||
|
|
||
| count = count + 1; | ||
| console.log(count) | ||
|
|
||
| // Line 1 is a variable declaration, creating the count variable with an initial value of 0 | ||
| // Describe what line 3 is doing, in particular focus on what = is doing | ||
| // Line 3 has been able to reassign the value of the count variable from 0 to 1. The operator = assign the new value to be stored as 1. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,7 @@ | ||
| const firstName = "Creola"; | ||
| const middleName = "Katherine"; | ||
| const lastName = "Johnson"; | ||
| const initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; | ||
|
|
||
| // 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. | ||
| console.log(initials); | ||
|
|
||
| const initials = ``; | ||
|
|
||
| // https://www.google.com/search?q=get+first+character+of+string+mdn |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,11 @@ const minimum = 1; | |
| const maximum = 100; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
| console.log(num); | ||
|
|
||
| // 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 | ||
| // 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 | ||
|
|
||
| // "num" variable carries the result/value of the expressions evaluated. | ||
| // (maximum - minimum) workout the size of the range: 100 - 1 + 1 = 100 | ||
| // Math.floor() takes out all decimal and make them a whole number from 0 to 99. | ||
| // Math.random() gives a decimal from 0 up to just under 1 (0.9999999). | ||
| // + minimum add 1 to the expression at the end because it is decleared a variable. | ||
|
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 revised explanation looks much better now. Just a few minor issues to fix further:
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 so much, I have fixed all errors now. |
||
| 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? | ||
|
|
||
|
|
||
| // This error is a syntaxError because javaScript could not understand the text. The error can be solved by commenting the lines using ("//") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // 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); | ||
|
|
||
| // This code returns a "TypeError: Assignment to constant variable.", because the variable age has been made constant and can't be manipulated. | ||
| // To solve the problem, we have to reassign the age variable from "const" to "let", that way it will allow for further manipulation and solve the error. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // 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}`); | ||
|
|
||
|
|
||
| // In this task, the variable was not assigned before attempting to print. Therefore, it gives the error "ReferenceError: Cannot access 'cityOfBirth' before initialization" | ||
| // The solution would be to assign the variable "cityOfBirth" first before printing the code. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = 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 | ||
| // 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 | ||
| // The variable cardNumber is not a string and the slice() function works with strings or array | ||
|
|
||
| // Consider: Why does it give this error? | ||
| // It gave that error "TypeError: cardNumber.slice is not a function" brcause the slice() function tool are not applicable to numbers. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const HourClockTime1 = "8:53pm"; | ||
| const hourClockTime2 = "20:53"; | ||
| console.log(`${HourClockTime1}, ${hourClockTime2}`) | ||
|
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. While this fixed the error, can you think of better variable names? Thank you.
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. Variable names changed, thank you |
||
|
|
||
| // The code displayed the error "SyntaxError: Invalid or unexpected token", this is because javaScript does not understand the variable name format. | ||
| // This error is solved by renaming the variable name starting it with an alphabet and avoiding starting the variable 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; | ||
|
|
@@ -13,10 +13,23 @@ console.log(`The percentage change is ${percentageChange}`); | |
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
|
|
||
| // Answer: Line 4 has 2 function call :'Number(), replaceAll()'. | ||
| // Line 5 has 2 function call: 'Number(), replaceAll()'. | ||
| // Line 10 has 1 function call console.log() | ||
| // In total there are 5 function calls. | ||
|
|
||
| // 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? | ||
| // Answer: The error is coming from line 5, spotting at the Number(priceAfterOneYear.replaceAll("," "")); | ||
| // It's a "SyntaxError: missing ) after argument list", missing a comma inside the replaceAll.() function. | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
|
|
||
| // Answer: Line 4 and 5 are variable assignment statements | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| // Answer: Line 1,2,7 and 8 are variable declearations | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
|
||
| // Answer: ReplaceAll() function clears out all the commas in the strings, the number() converts the strings to numbers to help with calculation | ||
|
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. JavaScript is case sensitive. It should be "The
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, Error corrcted. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,13 +13,27 @@ console.log(result); | |
|
|
||
| // a) How many variable declarations are there in this program? | ||
|
|
||
| // Answer: There is only 6 variable declearation altogether in this program | ||
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| // Answer: There is only 1 call function in this program console.log() | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // Answer: The % symbol represent the remainder (modulo) operator, it calculates the leftover/remainder after integer division. | ||
| // Answer: % 60 divides the movieLength by 60 and returns only the remainder. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| // Answer: Line 4 expression helps to eliminate any remainder from the equation, so its left with a clean multiple of 60 to avoid any decimal | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // Answer: It represent the total duration of the movie formatted into hours, minutes and seconds | ||
| // Answer: A better name could be "totalMovieDuration" | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| // Answer: It will work for integer values and will give us clear and clean result using this code. However, the result would not be clean as this using float values | ||
|
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. One more situation that make this program won't work well even an integer value is provided. Can you think of it?
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 will check and make research to see 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. How about this one? What integer values do not work for the program?
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. The program would not work for non-integers inputs. 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 answer mentioned that "It will work for integer values..." but some integer inputs would not work actually. So please identify what integers would work and what not. Thank you.
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 for pushing me to be better, I have been able to fix it by trying a negative value. I realise decimal and negative values breaks the code. Hopefully, that fix all errors |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,35 @@ console.log(`£${pounds}.${pence}`); | |
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
|
|
||
| // Answers: In line 1, a variable "penceString" was created holding the value "399p" | ||
|
|
||
| // In line 3-6, Another variable "penceStringWithoutTrailingP" was created to remove the trainling "p". | ||
| // That is, taking off the "p" in '399p' leaving it at just "399". | ||
|
|
||
| // Also, line 3-6 used the function substring(0, penceString.lrength - 1) to cut out the "p" in the "penceString" variable. | ||
| // By starting count fron 0 (beginnning) of "399p". | ||
| // "Using penceString.lenght - 1" to check the length of the value in the variable penceString = "399p" (4), | ||
| // And deducting 1 from the value (4 - 1), because length - 1 subtract 1 from the character/value count 4. leaving the value at "399" | ||
|
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. While the result of getting
Please revise your answer. Thank you.
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. My explanation is due to my level of understanding, I need to work on my terminologies usage going forward. Thank you 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. Much clearer and more accurate now, good job! Explaining code is an important skill as a software developer, and keep practicing and you will be fine. Cheers! |
||
|
|
||
| // Line 8 a variable "paddedPenceNumberString" was created and a function padStart(3, "0") | ||
| // was used to ensure the value of the variable remains at 3 and to be filled with "0" at the beginning if the value is less 3 | ||
|
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 understanding might be correct but the presentation seems not quite right. What does the "value" in your explanation "the value of the variable remains at 3" mean? Can you revise the wording a bit please? Thank you. p.s.: same issue with line 50-51 below, and please revise it as well.
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 so much for all your reviews, I really appreciate them and I have taken notes of the corrections. 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. Lines 50-51 now becomes lines 47-48, please fix them as well. Thank you. |
||
|
|
||
| // Line 9-12 created a variable "pounds" and used the subString(0, paddedPenceNumberString.length - 2 ) | ||
| // to start count from 0 of the "penceStringWithoutTrailingP" value which is 399. | ||
| // It further removed the last two number in the value by checking the length of the value with "paddedPenceNumberString.length" | ||
| // And subtracting 2 (3 - 2), because length - 2 subtract 2 from the character/value count. Cutting out 99 and leaving the value to remain 3. | ||
|
|
||
| // Line 14-16 created a variable "pence", using the subString(paddedPenceNumberString.length - 2) | ||
| // to check the length of the value of the variable "paddedPenceNumberString" which remain 399 from line 8 | ||
| // The "substring(paddedPenceNumberString.length - 2)" function deducts 3 leaving the last two numbers 99 | ||
| // PadEnd(2, "0") ensure the value remains 2 and 0 to be added to value less than 2. | ||
| // However, we already have in our "pence" variable at a value of 2 numbers "99" | ||
|
|
||
| // Line 18 printed our codes a formatted style adding the pound sign "£" | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| console.log("One fact i love about git is that it allows people to collaborate on projects"); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| console.log("In this exercise I will be learning different functions, and preactising them. "); | ||
|
|
||
| let userName = "Matthew"; | ||
| let location = "Manchester"; | ||
| let favoriteFood = "Jollof rice"; | ||
|
|
||
| function myInfo(userName, location, favoriteFood) { | ||
| console.log(`My name is ${userName}` ) | ||
| console.log(`I live in ${location}` ) | ||
| console.log(`My favorite food is ${favoriteFood}` ) | ||
| }; | ||
| myInfo(userName, location, favoriteFood); | ||
|
|
||
| sliceUserName = userName.slice(0, 4); | ||
| console.log(`My friends love to call me ${sliceUserName}`); | ||
|
|
||
| sliceLocation = location.lastIndexOf("h"); | ||
| console.log(sliceLocation); | ||
|
|
||
| const number1 = "50"; | ||
| const number2 = "100"; | ||
| const result = Number(number1) + Number(number2); | ||
| console.log(result); | ||
|
|
||
| let hobby = "I love football and traveling"; | ||
| let moreHobby = hobby.replaceAll("football", "swiming").replaceAll("traveling", "hiking"); | ||
| console.log(moreHobby); | ||
|
|
||
| const passion = hobby.substring(6, 15); | ||
| console.log(passion); | ||
|
|
||
| const luckyNumber = "7"; | ||
| const changeNumber = luckyNumber.padStart(5, "0"); | ||
| console.log(changeNumber); | ||
|
|
||
| const anotherNumber = luckyNumber.padEnd(5, "0"); | ||
| console.log(anotherNumber); | ||
|
|
||
| const carPrice = 30000.50; | ||
| const updatedCarPrice = Math.floor(carPrice); | ||
| console.log(updatedCarPrice); | ||
|
|
||
| const addNumber = 20; | ||
| const addNumber2 = 30; | ||
| const addNumber3 = addNumber + addNumber2; | ||
| const addNumberResult = Math.random() * addNumber3 | ||
| console.log(addNumberResult); | ||
|
|
||
| const repeatedText = "one, two, three"; | ||
| const lastOnePosition = repeatedText.lastIndexOf("one"); | ||
| console.log(lastOnePosition); | ||
|
|
||
| // const yourName = prompt("Please enter your name: "); | ||
| // const yourLocation = prompt("Please enter your location: "); | ||
| // const yourHobby = prompt("Enter your hobby: "); | ||
| // const yourFavoriteFood = prompt("Please enter your favorite food: ") | ||
|
|
||
| // function userInfo(yourName, yourLocation, yourHobby, yourFavoriteFood) { | ||
| // console.log(`Your name is ${yourName}`) | ||
| // console.log(`You live in ${yourLocation}`) | ||
| // console.log(`Your hobby is ${yourHobby}`) | ||
| // console.log(`Your favorite food is ${yourFavoriteFood}`) | ||
| // } | ||
|
|
||
| // userInfo(yourName, yourLocation, yourHobby, yourFavoriteFood) | ||
| // Chrome devOps prompt function, variable and parameters |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| const greeting = "Hello There !"; | ||
| console.log(greeting); | ||
|
|
||
| const name = "Matt"; | ||
| console.log(`${greeting}, I am ${name}`); | ||
|
|
||
| let location = "Manchester"; | ||
| console.log(`${greeting}, my name is ${name} and i live in ${location} `); | ||
|
|
||
| let location2 = "London"; | ||
| console.log(`${greeting}, I am ${name}, I will be traveling to ${location2} soon`); | ||
|
|
||
| console.log("Dog" === "Mango"); | ||
|
|
||
| console.log(5 + 15 === 20); | ||
|
|
||
| console.log("dog" == "dog"); | ||
|
|
||
| console.log(40+5 == "45"); | ||
|
|
||
| console.log(60+40 > 50); | ||
|
|
||
| console.log(100<= 90); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| const password = "Matt123"; | ||
| const userInput = "Anything"; | ||
| const administrator = "Anything"; | ||
| let response = " "; | ||
|
|
||
| if (password === userInput) { | ||
| response = "Login successful"; | ||
| } else if (userInput === administrator) { | ||
| response = "Welcome to the site"; | ||
| } | ||
| else { | ||
| response = "Please try again"; | ||
| } | ||
| console.log(response); | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,23 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // ======> write your prediction here: I predict that the code should cut out, and make the first letter of the string an uppercase letter, | ||
| // then add every letters that comes after | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| // function capitalise(str) { | ||
| // let str= `${str[0].toUpperCase()}${str.slice(1)}` | ||
| // return str; | ||
| // } | ||
|
|
||
|
|
||
| // =============> write your explanation here: The error read "SyntaxError: Identifier 'str' has already been declared", | ||
| // this is as a result of having two variables with same name. The error occoured in this code because the variable "str" has been decleared twice | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
|
|
||
| function capitalise(str) { | ||
| let str2= `${str[0].toUpperCase()}${str.slice(1)}` | ||
| return str2; | ||
| } | ||
| console.log(capitalise("money")) |
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.
The file name does not necessary 4 characters long. It can be longer and shorter (e.g. considering
/path/to/screenshot.png). Cutting out the first 4 characters does not necessary remain the file extension. Please fix it, thank you.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 this review, I have checked and found out the right solution. Appreciate
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.
The revised solution is much better. However, according to definition in line 7, the
.should also be considered as file extension. So please fix this minor issue as well. Thank you.