-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
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 |
---|---|---|
@@ -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 |
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)); |
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)}`); |
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)}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,22 +10,23 @@ function formatTimeDisplay(seconds) { | |
|
||
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 | ||
// =============> write your answer here. one time | ||
|
||
// 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 | ||
// =============> write your answer here .is 60 | ||
|
||
// c) What is the return value of pad is called for the first time? | ||
// =============> write your answer here | ||
// =============> write your answer here is 0 | ||
|
||
|
||
// 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 | ||
|
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.