generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 219
Glasgow | 25-ITP-SEP | Shreef Ibrahim | Sprint 2 | Coursework #705
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
Open
shreefAhmedM
wants to merge
4
commits into
CodeYourFuture:main
Choose a base branch
from
shreefAhmedM:acoursework/sprint-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+167
−48
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
|
||
// Its retrurn an error | ||
// call the function capitalise with a string input | ||
// 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; | ||
} | ||
// function capitalise(str) { | ||
// let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
// return str; | ||
// } | ||
|
||
// =============> write your explanation here | ||
// SyntaxError: Identifier 'str' has already been declared | ||
// =============> write your new code here | ||
function capitalise(str) { | ||
let formatedStr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return formatedStr; | ||
} | ||
console.log(capitalise("info")) //==> Info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
// Predict and explain first... | ||
|
||
// =============> write your prediction here | ||
// =============> write your prediction // The result of multiplying 10 and 32 is undefined | ||
|
||
function multiply(a, b) { | ||
console.log(a * b); | ||
} | ||
|
||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// When `multiply(10, 32)` is called inside the template string, | ||
// it runs the function (which logs `320`), but since it doesn't return anything, | ||
// it inserts `undefined` into the string. | ||
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
function multiply(a, b) { | ||
return `The result of multiplying ${a} and ${b} is ${a * b}` | ||
} | ||
console.log(multiply(10, 32)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// =============> it returns undefined, Because a + b line is never executed | ||
|
||
function sum(a, b) { | ||
return; | ||
a + b; | ||
} | ||
// function sum(a, b) { | ||
// return; | ||
// a + b; | ||
// } | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// Because there's a line break after `return`, the `a + b;` line is never executed. | ||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
|
||
function sum(a, b) { | ||
return a + b; | ||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
// Predict and explain first... | ||
|
||
// Predict the output of the following code: | ||
// =============> Write your prediction here | ||
// =============> Write your prediction here .eturn undefiend | ||
|
||
const num = 103; | ||
// const num = 103; | ||
|
||
function getLastDigit() { | ||
return num.toString().slice(-1); | ||
} | ||
// function getLastDigit() { | ||
// return num.toString().slice(-1); | ||
// } | ||
|
||
console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
// console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
// console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
// console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
||
// Now run the code and compare the output to your prediction | ||
// =============> write the output here | ||
// Explain why the output is the way it is | ||
// =============> write your explanation here | ||
// =============> write your explanation here. doesn't take any parameters, so it always uses the constant `num = 103`. | ||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
|
||
// This program should tell the user the last digit of each number. | ||
// Explain why getLastDigit is not working properly - correct the problem | ||
|
||
function getLastDigit(num) { | ||
return num.toString().slice(-1); | ||
} | ||
|
||
console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
function pad(num) { | ||
return num.toString().padStart(2, "0"); | ||
|
||
} | ||
|
||
function formatTimeDisplay(seconds) { | ||
const remainingSeconds = seconds % 60; | ||
const totalMinutes = (seconds - remainingSeconds) / 60; | ||
const remainingMinutes = totalMinutes % 60; | ||
const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
|
||
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; | ||
} | ||
formatTimeDisplay(60); | ||
|
||
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit | ||
// to help you answer these questions | ||
|
||
// Questions | ||
|
||
// a) When formatTimeDisplay is called how many times will pad be called? | ||
// =============> write your answer here | ||
// =============> 3 times | ||
|
||
// Call formatTimeDisplay with an input of 61, now answer the following: | ||
|
||
// b) What is the value assigned to num when pad is called for the first time? | ||
// =============> write your answer here | ||
// =============> .is 0 ,because totalHours = 0 at that point. | ||
|
||
// c) What is the return value of pad is called for the first time? | ||
// =============> write your answer here | ||
// =============> is "00" | ||
|
||
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer | ||
// =============> write your answer here | ||
// =============> num = 1 ,because last call to pad is for remainingMinutes, which is = 1 | ||
|
||
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer | ||
// =============> write your answer here | ||
// =============> "01" because pad(1) converts 1 to a string and pads it to two digits, resulting in "01" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Indentation is a bit off.
It is a common practice to begin variable names with a lowercase letter. Names that start with an uppercase letter are typically reserved for user-defined data types or class names.