-
-
Notifications
You must be signed in to change notification settings - Fork 314
London | Jan2026 | Ihor Taradaiko | Sprint 1 | Coursework/sprint 1 #934
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
c16be64
9b0dde9
2af0341
82eeb81
b0a547c
b710983
9514edf
a13b666
ff43f7d
6cd17cc
4a7731e
2727395
e401a84
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 |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ 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 = ``; | ||
| let initials = `${firstName.charAt()}${middleName.charAt()}${lastName.charAt()} `; | ||
|
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. Normally, we specify an argument in the function call Can you find out why the statement on line 8 can still work? We don't recommend this practice. Can you update the code on line 8 to explicitly pass an argument to each function |
||
| 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 |
|---|---|---|
|
|
@@ -2,8 +2,10 @@ 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 | ||
| //results: 4,23,91,46 the program is giving you a random number while math.random give you a random decimal number math.floor rounds the total number up | ||
|
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 give a precise description what each of these expressions does, and the range of the numbers it may produce?
Note: To describe a range of numbers, we can use the concise and precise interval notation:
For example, |
||
| 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? | ||
| // comment them |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
| let age = 33; | ||
| age = age+1 | ||
| console.log(age) | ||
|
|
||
| //const sets the value as a constant you can't change |
| 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 ? | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| //wrong order |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| function digits() { | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = String(cardNumber).slice(-4); | ||
| return last4Digits; | ||
| }console.log(digits()) | ||
| // 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 | ||
|
|
||
| //Numbers don’t have .slice(), so we convert the number to a string |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,9 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| // const 12HourClockTime = "20:53"; | ||
| // const 24hourClockTime = "08:53"; | ||
|
|
||
| //answer | ||
|
|
||
| const HourClockTime24 = "20:53"; | ||
| const hourClockTime12 = "08:53"; | ||
|
Comment on lines
+6
to
+7
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. In JS naming convention, variable names usually begins with a lowercase letter. Names starting with an uppercase letter are used for built-in and custom data types (e.g., |
||
|
|
||
| // you can't start a parameter with the number, also the values did not match logically to the parameter | ||
| 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,12 @@ 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 | ||
|
|
||
| //4,5,11 | ||
|
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 also indicate the total number of function calls? (It is not three). |
||
| // 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? | ||
|
|
||
| //line 5, added come before "" | ||
| // c) Identify all the lines that are variable reassignment statements | ||
|
|
||
| //4,5 | ||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| //1,2,7,8 | ||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| //removes commas / Converts the string "10000" into the number | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = 2600; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
@@ -12,14 +12,16 @@ 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 | ||
| // b) How many function calls are there? | ||
|
|
||
| // | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| //The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| //math expression | ||
|
Comment on lines
22
to
+23
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 question means to ask, "what does |
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| //maybe timeLeft or similar | ||
|
Comment on lines
-24
to
+25
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. When I see a variable named
Can you think of a more meaningful name that could more accurately describe the value it stores. |
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,23 @@ | ||
| const penceString = "399p"; | ||
|
|
||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| const penceStringWithoutTrailingP = penceString.substring( | ||
| 0, | ||
| penceString.length - 1 | ||
| ); | ||
|
|
||
| //2. removes "P" from the string | ||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| //3. Ensures the string is at least 3 characters long by adding 0 to the start | ||
| const pounds = paddedPenceNumberString.substring( | ||
| 0, | ||
| paddedPenceNumberString.length - 2 | ||
| ); | ||
|
|
||
| //4. Extracts everything except the last 2 digits of paddedPenceNumberString | ||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); | ||
|
|
||
| //5. takes the last 2 digits as the pence from paddedPenceNumberString | ||
|
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}`); | ||
| //6. Prints the formatted pounds-and-pence value | ||
|
|
||
| // This program takes a string representing a price in pence | ||
| // The program then builds up a string representing the price in pounds | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,8 @@ In the Chrome console, | |
| invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
|
||
| What effect does calling the `alert` function have? | ||
|
|
||
| //Shows an alert | ||
| 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`? | ||
| //shows a pop-up to enter a name / stores and shows name | ||
| What effect does calling the `prompt` function have? //shows pop-up form | ||
| What is the return value of `prompt`? //if myName is set returns myName value | ||
|
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 describe the return value of The current description does not quite tell me exactly what the function returns. |
||
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?