-
-
Notifications
You must be signed in to change notification settings - Fork 262
West Midlands | ITP-Sept-2025 | Ali Naru | Sprint 3 | Coursework/sprint-1 #770
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
Changes from 12 commits
07c5cbe
7bca1d2
2b57ffd
76e3f65
afca59a
2b12a34
b7a8c22
993c40c
d8109f2
13c32aa
5f6ff93
f4d3f59
a33085b
b401592
6106da7
e2f242e
bd66e0c
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,10 @@ 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(lastSlashIndex); | ||
|
||
|
|
||
|
|
||
| console.log(`The dir part of ${filePath} is ${dir}`); | ||
| console.log(`The ext part of ${filePath} is ${ext}`); | ||
| // https://www.google.com/search?q=slice+mdn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,31 @@ 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? | ||
|
|
||
| //After running this exercise a few times I can see that 'num' is a random number between 1 and 100 | ||
|
|
||
| console.log(num); | ||
|
|
||
| // Try breaking down the expression and using documentation to explain what it means | ||
|
|
||
| // at the top we can see our minimum and maximum values which are fixed therefore Constants, | ||
| // we then have our variable num which is assigned a value using the Math object and its methods floor and random | ||
| // Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive) | ||
|
||
| // We then multiply this random number by the range of our desired numbers which is (maximum - minimum + 1) | ||
|
|
||
| // It will help to think about the order in which expressions are evaluated | ||
|
|
||
| //the same as math, multiplication is done before addition and subtraction | ||
| // so we first calculate (maximum - minimum + 1) which is (100 - 1 + 1) = 100 | ||
| // then we multiply the random decimal number by 100 which gives us a number between 0 and 100 (but not including 100) | ||
| // then we apply Math.floor() to round down to the nearest whole number, giving us a number between 0 and 99 | ||
| // finally we add the minimum value (1) to shift the range up, resulting in a final value between 1 and 100 (inclusive) | ||
|
|
||
| // So in summary, 'num' is a random integer between 1 and 100, inclusive of both endpoints. | ||
|
|
||
|
|
||
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| //you can see how random function generates different numbers each time the program is run | ||
| //and how the range is always between 1 and 100 | ||
|
|
||
| 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? | ||
| ///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? | ||
|
|
||
| // in code use backslashes to create comments. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; // changed from constant to variable so that value can be reassigned | ||
| age = age + 1; | ||
| console.log(age); // should print 34 running testing | ||
|
|
||
|
|
||
| //after testing can confirm age variable is now 34. |
| 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 | ||
| // CardNumber is not a funtion so it does not have the method slice. | ||
|
|
||
| // Then run the code and see what error it gives. | ||
| // TypeError: cardNumber.slice is not a function | ||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| //this is what I predicted because slice is a method for strings and arrays, not numbers. | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
|
|
||
|
|
||
| const last4DigitsCorrected = cardNumber.toString().slice(-4); | ||
|
|
||
| console.log(last4DigitsCorrected); // Should output: 4213 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const Twelve_HourClockTime = "20:53"; | ||
| const Twenty_Four_hourClockTime = "08:53"; | ||
|
||
|
|
||
| //Variables cannot have numbers at the start of their name | ||
| //the times are in the wrong format for their variable names | ||
|
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. This file is not related to Sprint-1 exercise. Can you revert the changes made to the file to keep this branch clean?
Author
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 believe I have now reverted the file, I accidentally worked on that file before creating a new branch for sprint 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. The file is still in this branch.
Author
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 have now reverted it back to main so this file should no longer be there, please review. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,28 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> write your prediction here: | ||
| // I think their will be an error because of the str tag | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // call the function capitalise with a string input | ||
| console.log(capitalise("hello")); // should print "Hello" | ||
|
|
||
|
|
||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| //function capitalise(str) { | ||
| //let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| //return str; | ||
| //} | ||
|
|
||
| // =============> write your explanation here: | ||
| // str is being used as both the function parameter and a variable inside the function, causing a conflict. | ||
|
|
||
|
|
||
| // =============> write your new code here | ||
|
|
||
| function capitalise(inputStr) { | ||
| return `${inputStr[0].toUpperCase()}${inputStr.slice(1)}`;} |
Uh oh!
There was an error while loading. Please reload this page.