-
-
Notifications
You must be signed in to change notification settings - Fork 197
Sheffield | May-2025 | Hassan Osman | Sprint-1 #469
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 15 commits
209ea8f
cf11f38
9751116
c263fad
8ab5a4e
e8108f8
5c1b48b
2a36aae
064ecb3
547fbeb
608f18d
47d435e
408a4f2
e57e590
d1e40e4
b0469be
a6e7a48
1042135
6dd1748
a6bfabe
41eff9e
d94c7bd
5203cb7
616652d
ec14852
7c5701d
c93411c
a9cdc03
cac3613
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 |
---|---|---|
|
@@ -7,3 +7,15 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | |
// 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 | ||
|
||
/* | ||
1. num represents any random whole number (integer) between 1 and 100 (both included) | ||
2. Math.floor(x) it rounds down x to a value that is less than or equal to x, while Math.random() it generates random | ||
numbers that are equal to 0 and less than 1. | ||
3. before we multiply (Math.random() by (maximum - minimum + 1) or vice versa, each expression gets evaulated | ||
first on its own. Math.random() leads to an integer between 0 and less 1, while (maximum - minimum + 1)) evaluates | ||
to 100. Then multiplication comes into place and we get floats from 0.00 and less than 100. Having Math.floor() | ||
as a method basically means we now have random integers from 0 and 99. By considering the last part of the value | ||
assigned to num, we now have random integers from 1 and 100 (both included). | ||
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 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. Done |
||
4. Done! | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
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? | ||
|
||
/* | ||
I got "SyntaxError: Unexpected identifier" error message. It happen because the 2 lines don't make sense. | ||
the computor sees the first word and it assumes a variable or a function is being declared but then when | ||
it reads the resut of the sentence it breaks as this is not how an identifier is being used and formed in | ||
a programme. | ||
To avoid this issue, we can just simply comment the 2 lines, just like what I am doing here! | ||
|
||
*/ | ||
|
||
/* | ||
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? | ||
*/ | ||
|
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.slice(-4); | ||
|
||
// 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 | ||
|
||
|
||
/* | ||
This error message was thrown after running the code "TypeError: cardNumber.slice is not a function". | ||
It simply happned because ".slice()" is not a method associated with integers but strings & arrays. | ||
To avoid this issue the value of last4Digits should be as below: | ||
*/ | ||
|
||
const last4Digits = cardNumber.toString().slice(-4); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
//const 12HourClockTime = "20:53"; | ||
//const 24hourClockTime = "08:53"; | ||
|
||
// to avoid the syntax error after running the above lines of code do as below: | ||
|
||
const ClockTime12Hour = "20:53"; | ||
const ClockTime24hour = "08:53"; | ||
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 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. Changed this now. |
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; | ||
|
@@ -20,3 +20,18 @@ console.log(`The percentage change is ${percentageChange}`); | |
// d) Identify all the lines that are variable declarations | ||
|
||
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
||
/* | ||
a) There are 5 at: 1)carPrice = Number(carPrice.replaceAll(",", "")); & 2)priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")), | ||
3) & 4) const priceDifference = carPrice - priceAfterOneYear; 5) const percentageChange = (priceDifference / carPrice) * 100; | ||
|
||
b) The error happened due to the missing comma "," in between the 2 parameters/arguments in line 5's function call. Just add a comma to solve | ||
this problem. | ||
|
||
c) line 4 & line 5 | ||
|
||
d) line 1 & line 2 | ||
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 7 and 8 are also declarations, although they are not really "variables". |
||
|
||
e) The last expression gets rid of all the commas present in the declared variables in line 1 & 2. or in other words, replaces them commas with | ||
no space between the characters separated by the commas. | ||
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 ask ChatGPT to describe the code at line 5, and see if you can use something it suggests in your description? 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. Done! |
||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const movieLength = 8784; // length of movie in seconds | ||
const movieLength = -10; // length of movie in seconds | ||
|
||
const remainingSeconds = movieLength % 60; | ||
const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
@@ -23,3 +23,14 @@ console.log(result); | |
// e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
||
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
||
|
||
/* | ||
a) There are 6 in total. | ||
b) 0 function calls. | ||
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 number of function calls is more than 0. |
||
c) it represents the remainder from the division of movieLength by 60. | ||
d) line 4 represents the total number of mins in the movie (as whole numbers -integers) by getting rid of the decimal parts (in secs). | ||
e) Result represents the total movie duration (in exact hours, exact min and exact sec). movieDuration could be a good name. | ||
f) it works. However, if there's enough time to form a whole hour(s) for example the results shows the total mins and total secs and so | ||
on. So I'd say it works. | ||
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 do you mean by this statement? 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 was basically trying to say that it does work for all movie durations. However, and that depending on the value you may end up with 0 for the hour part and only values for the mins and secs or 0 for both hours and mins and only value for secs for even 0 for all hour, min & sec parts (if movieLength = 0 secs). Anyway, i've rephrased and simplified my response now. |
||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,12 @@ In the Chrome console, | |
invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
||
What effect does calling the `alert` function have? | ||
// a message with Hello world! message pops up in a small Chrome notification window | ||
|
||
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`. | ||
// small Chrome window pops up with "What is your name?" and underneath it a space for the user to enter and submit their name. | ||
|
||
What effect does calling the `prompt` function have? | ||
//prompt expect input from the user by showing a small window with space for input to be submitted once called. | ||
What is the return value of `prompt`? | ||
//undefined | ||
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. Note: To view the return value of a function call, you need to output the return value to the console as You can also find out exactly what the function returns from the MDN Web Docs website. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,19 @@ In this activity, we'll explore some additional concepts that you'll encounter i | |
|
||
Open the Chrome devtools Console, type in `console.log` and then hit enter | ||
|
||
What output do you get? | ||
What output do you get? | ||
//ƒ log() { [native code] } | ||
|
||
Now enter just `console` in the Console, what output do you get back? | ||
// console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} | ||
|
||
Try also entering `typeof console` | ||
// got 'object' as an output | ||
|
||
Answer the following questions: | ||
|
||
What does `console` store? | ||
//console doesn't store. it displays. | ||
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 is asking what kind of properties are stored in the |
||
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? | ||
//console.log log or display values to the console. Console.assert, check if a condition is true and in this case no output. Otherwise, an | ||
// error message shows. As for the `,`, it's called the dot notation and it's used to access properties and methods of an object. |
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 + 1
is 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.
Done!