-
-
Notifications
You must be signed in to change notification settings - Fork 330
Sheffield | 26-Jan-ITP | Karim Mhamdi | Sprint 1 | Coursework/sprint-1 #1092
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 |
|---|---|---|
|
|
@@ -17,7 +17,9 @@ console.log(`The base part of ${filePath} is ${base}`); | |
| // Create a variable to store the dir part of the filePath variable | ||
| // Create a variable to store the ext part of the variable | ||
|
|
||
| const dir = ; | ||
| const ext = ; | ||
| const dir = filePath.slice(0, lastSlashIndex); | ||
| const ext = filePath.slice(filePath.lastIndexOf(".")) ; | ||
|
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. Code is correct. On line 21, there are some trailing space characters. If you enabled "Format on save" in VSCode, and you have installed "prettier" extension, VSCode can automatically indent the code and remove all trailing space characters. |
||
|
|
||
| console.log("dir:", dir); | ||
| console.log("ext:", ext); | ||
| // https://www.google.com/search?q=slice+mdn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,16 @@ const maximum = 100; | |
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| console.log(num); | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // num represents a random whole number between the minimum and maximum values. | ||
|
|
||
| // 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 | ||
|
|
||
| //Step 1 Generate a random decimal between 0 and 1 | ||
| //step 2 multiplys the random decimal by 100 - 1 = 99 + 1 = 100 | ||
| //step 3 math.floor makes it a whole number between 0 and 99 | ||
| //step 4 adds 1 to make it a whole number between 1 and 100 | ||
|
Comment on lines
+15
to
+18
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. Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included. We can use the concise and precise interval notation to describe a range of values.
For example, |
||
| 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? | ||
| 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,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,5 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
| // what's the error ? The error is that the string is not being printed to the console because there is no console.log statement to output it. | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| console.log("I was born in Bolton"); | ||
| const cityOfBirth = "Bolton"; | ||
|
Comment on lines
-4
to
5
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 reason you gave does not quite explain why the original code does not work. What was the error message reported by the JS runtime? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,18 @@ | ||
| 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 | ||
|
|
||
| /* | ||
| Prediction: It wont work because cardNumber is a number and slice() only works on strings. | ||
| Error: TypeError - cardnumber.slice is not a function. | ||
| Explanation: Numbers dont have the slice method. | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const hour12HourClockTime = "20:53"; | ||
| const hour24HourClockTime = "08:53"; |
| 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,22 @@ 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 | ||
| // Line 4 has a function call | ||
| // Line 5 has a function call | ||
| // line 10 has a function call | ||
|
|
||
| // 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? | ||
| // I have spotted the error in line 5 becouse there was a missing comma inside the brackets. | ||
|
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. Can you revise the description to indicate where inside the brackets (parentheses) the comma is missing? (e.g., the comma is missing between the ___________ ) |
||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // Line 4 and line 5 are variable reassignment statements. | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| // Line 1 | ||
| // Line 2 | ||
| // line 7 | ||
| // line 8 | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // The purpose of this expression is to remove the commas from the string value using the replaceAll(). | ||
|
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. What about the |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,24 @@ 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? | ||
| // There is 6 Variable declarations | ||
| // Line 1 , Line 3 , Line 4 , Line 6 , Line 7 , Line 9 | ||
|
|
||
| // b) How many function calls are there? | ||
| // There is 1 function call in Line 10 | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // The expression movieLength % 60 represents the remainder of the division of movieLength by 60. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // Line 4 removes the leftover seconds, then devides by 60. | ||
| // then divides the result by 60 to calculate the total full minutes. | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // Result is a formatted time string in hours minutes and seconds. | ||
|
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 are two questions in part (e). Can you also answer the second question? |
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // I tested diffrent positive numbers and the code work correctly. | ||
| // However it well work properly for positive numbers. | ||
| // If movielength is negative or a decimal number , the output may not repeesent the time correctly. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,13 @@ 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 | ||
| // 1. Stores "399p" as a string | ||
| // 2. removes the "p" at the end | ||
| // 3. adds zeros at the start if needed to make it 3 digits. | ||
| // 4. Takes everything except the last 2 digits as pounds. | ||
| // 5. Prints the result in this format: £3.99 | ||
|
Comment on lines
+28
to
+29
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. (4) and (5) does not quite describe the code on lines 14-16. Also, could we expect this program to work as intended for any valid |
||
|
|
||
| // To begin, we can start with | ||
| // I also tested it by changing 399p to 50p and the result was £0.50 thats shows diffrent numbers well have diffrent outputs | ||
|
|
||
| // To begin, we can start wit | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,10 @@ Let's try an example. | |
| In the Chrome console, | ||
| invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
|
||
| What effect does calling the `alert` function have? | ||
| What effect does calling the `alert` function have? It displays a popup message box with a text saying Hello world! and pauses the website in until you click ok to unpause it. | ||
|
|
||
| Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. | ||
|
|
||
| What effect does calling the `prompt` function have? | ||
| What is the return value of `prompt`? | ||
| What effect does calling the `prompt` function have? The prompt function displays a popup box asking you to enter a text and pausing the page until you click ok or cancel. | ||
|
|
||
| What is the return value of `prompt`? Prompt returns the text entered by the user as a string if the user clicks cancel. | ||
|
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 answer does not look correct. Can you revise it? |
||
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.
Operation like
count = count + 1is very common in programming, and there is a programming term describing such operation.Can you find out what one-word programming term describes the operation on line 3?
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 the feedback I well work on it and and I well put a better description
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 description is good. I just want everyone to know the relevant programming term.