London | ITP-JAN-2026 | Said Fayaz Sadat | Sprint 1 | coursework/sprint 1#997
London | ITP-JAN-2026 | Said Fayaz Sadat | Sprint 1 | coursework/sprint 1#997fayaz551 wants to merge 4 commits intoCodeYourFuture:mainfrom
Conversation
| // Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive). So it can be any value from 0 up to but not including 1. | ||
| // (maximum - minimum + 1) calculates the range of possible values, which is 100 - 1 + 1 = 100. This means we want to generate a random number between 0 and 99 (inclusive) before adding the minimum value. | ||
| // Math.random() * (maximum - minimum + 1) gives us a random decimal number between 0 (inclusive) and 100 (exclusive). This means it can be any value from 0 up to but not including 100. | ||
| // Math.floor() takes the random decimal number and rounds it down to the nearest whole number. This means we will get an integer value between 0 and 99 (inclusive). | ||
| // Finally, we add the minimum value (1) to the result, which shifts the range from 0-99 to 1-100. So num will be a random integer between 1 and 100 (inclusive). No newline at end of file |
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(last4Digits); No newline at end of file |
There was a problem hiding this comment.
Good way to go about the solution without redeclaring the variable
| // | ||
| // The code above won't work because the variable names suggest that twelveHourClockTime should represent a time in 12-hour format, while twentyFourHourClockTime should represent a time in 24-hour format. However, the values assigned to these variables are not consistent with their names. To fix this error, we can either change the variable names to match the values or update the values to match the variable names. For example: | ||
|
|
||
| const twelveHourClockTime = "08:53 PM"; |
There was a problem hiding this comment.
Good observation to both variable name and time format
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
| // There are 4 function calls in this file. The lines where a function call is made are: | ||
| // Line 1: carPrice.replaceAll(",", "") | ||
| // Line 2: priceAfterOneYear.replaceAll(",", "") | ||
| // Line 3: Number(carPrice.replaceAll(",", "")) | ||
| // Line 4: Number(priceAfterOneYear.replaceAll(",", "")) |
There was a problem hiding this comment.
Can you have a look again and see if you would notice a different number of function calls within the code block?
| // Line 4: Number(priceAfterOneYear.replaceAll(",", "")) | ||
|
|
||
| // 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 occurring on 4 where we are trying to convert the string values of carPrice and priceAfterOneYear to numbers using the Number function. The error is occurring because the replaceAll method is being called on a string that has not been updated with the new value after the first replaceAll call. To fix this problem, we can update the carPrice and priceAfterOneYear variables with the new values after the replaceAll calls. For example: |
There was a problem hiding this comment.
Have a look at the code in the task again and re-evaluate the answer to the question.
|
|
||
| // The variable result represents the formatted string that shows the length of the movie in hours, minutes, and seconds. A better name for this variable could be formattedMovieLength or movieDurationFormatted, as it more clearly indicates that it is a formatted representation of the movie length. | ||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // This code will work for all non-negative integer values of movieLength, as it is designed to convert a length in seconds into a format of hours, minutes, and seconds. However, if movieLength is a negative value, the calculations may not make sense in the context of a movie length, and the output may not be meaningful. No newline at end of file |
There was a problem hiding this comment.
Can you also think of any scenario where some positive integer values may not produce a good output when applied?
| Open the Chrome devtools Console, type in `console.log` and then hit enter | ||
|
|
||
| What output do you get? | ||
| function defination | ||
|
|
||
|
|
||
| Now enter just `console` in the Console, what output do you get back? | ||
| This prints the entire console object with all its methods, like log, warn, error, etc. | ||
|
|
||
| Try also entering `typeof console` | ||
| This prints the entire console object with all its methods, like log, warn, error, etc. |
There was a problem hiding this comment.
Let your comment contain the actual output gotten from running the operation in the task.
| console.log("Hello") calls the log method to print something to the console. | ||
|
|
||
| console.assert(condition, "Message") calls the assert method to check a condition, and only prints the message if the condition is false. |
There was a problem hiding this comment.
You need to answer the questions according to the task requirement. Go through the question again and give a more direct answer.
Theoreoluwa
left a comment
There was a problem hiding this comment.
Very well done, Said. Please take a look at the comments attached to make it better.
Learners, PR Template
Self checklist
Changelist
i have completed all 4 exercises of sprint 1 with explanation and working code as well.
Questions
n/a