-
-
Notifications
You must be signed in to change notification settings - Fork 314
London | 26-ITP-Jan | Oussama Mouggal | Sprint 1 | Coursework #948
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
9886ffc
ee71142
5d661c5
8c004f3
e9b4f5d
01fb6ae
e662361
ef076e0
587429d
98f4de9
0ed56e5
9e74f96
0c994bb
1a7e2ed
ba27648
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 |
|---|---|---|
|
|
@@ -2,8 +2,7 @@ const minimum = 1; | |
| const maximum = 100; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
| console.log(num) | ||
|
|
||
| //In this exercise num is a variable that stores a random integer between 1 and 100. | ||
|
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 also use the concise and precise interval notation to describe a range of values.
For example, |
||
|
|
||
| // 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| 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 commented out the 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; | ||
| age = age + 1; | ||
| Newage = (age + 1); | ||
|
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.
|
||
| console.log(Newage) | ||
| 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 ? | ||
|
|
||
| let cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
| 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. Why change the original If a variable is not going to be reassigned any value, best practice is to declare it using |
||
| //The error was because the variable was declared after the consol.log | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const TwelveHourClockTime = "20:53"; | ||
| const TwentyfourHourClockTime = "08:53"; | ||
|
Comment on lines
+1
to
+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. Names starting with an uppercase letter are reserved (by convention) for built-in and custom data types. Can you change the names? |
||
| //The errors in the code were that variables can't start with numbers. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,21 @@ 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; | ||
|
|
||
| console.log(`The percentage change is ${percentageChange}`); | ||
|
|
||
| //a) There are 4 function calls in this file. They are on lines 1, 2, 4, and 5. | ||
| //b) The error is in line 4 and 5. The error is occurring because the replaceAll function is being called on a string, | ||
| // but the string has not been converted to a number. | ||
|
Comment on lines
+13
to
+14
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 syntax error is on line 5, and the reason is because a comma ( Can you find out what this programming term is? |
||
| //c) The variable reassignment statements are in lines 4 and 5 | ||
| //d) The variable declarations are in lines 1,2,7, and 8. | ||
| //e) The expression Number(carPrice.replaceAll(",","")) is converting the string carPrice into a number | ||
| // by removing the commas and then converting the resulting string into a number. from "10,000" to "10000" to 10000 | ||
|
|
||
| // 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,18 @@ const totalHours = (totalMinutes - remainingMinutes) / 60; | |
| const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| console.log(result); | ||
|
|
||
| //Answers: | ||
| //a) There are 6 variable declarations in this program. They are on lines 1,3,4,6,7, and 9. | ||
| //b) There is 1 function call in this program. It is on line 9. | ||
| //c) The expression movieLength % 60 represents the remainder when movieLength is divided by 60. | ||
| //d) The expression convert the total movie length into minutes, ignoring the leftover seconds. | ||
| //e) The variable result represents the total length of the movie in hours, minutes, and seconds. | ||
| // a better name is movieLength | ||
|
Comment on lines
+17
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. The name
Can you think of a more descriptive name? |
||
| //f) This code work perfectly for positive numbers> However, it doesn't work for negative or very large numbers, and decimals. | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // 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? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,25 @@ | ||
| const penceString = "399p"; | ||
|
|
||
| // it creates a string representing a price in pence,the p at the end indicates the unit. | ||
| const penceStringWithoutTrailingP = penceString.substring( | ||
| 0, | ||
| penceString.length - 1 | ||
| ); | ||
|
|
||
| // it removes the trailing "p" from the penceString, leaving only the numeric part of the string. | ||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| //Insure the numeric string has at least 3 characters, padding it with 0 if needed. | ||
| const pounds = paddedPenceNumberString.substring( | ||
| 0, | ||
| paddedPenceNumberString.length - 2 | ||
| ); | ||
|
|
||
| // Takes all digits except the last two to represent the pounds part of the price. | ||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); | ||
|
|
||
| // Takes the last two digits to represent the pence part of the price, ensuring it has two characters. | ||
|
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. Could we expect this program to work as intended for any valid |
||
| console.log(`£${pounds}.${pence}`); | ||
| // it logs the final price in pounds and pence format : "£3.99" | ||
|
|
||
|
|
||
|
|
||
| // This program takes a string representing a price in pence | ||
| // The program then builds up a string representing the price in pounds | ||
|
|
||
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?