-
-
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 1 commit
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)}`); |
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. Why renamed this file? 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 renamed by mistake, i have updated to 1-bmi.js |
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,25 @@ | |
// Make sure to do the prep before you do the coursework | ||
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. | ||
|
||
|
||
function formatAs12HourClock(time) { | ||
const hours = Number(time.slice(0, 2)); | ||
if (hours > 12) { | ||
return `${hours - 12}:00 pm`; | ||
const minutes = time.slice(3); | ||
let currTime = "am"; | ||
let HoursModefied = hours; | ||
cjyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
if (hours === 0) { | ||
HoursModefied = 12; | ||
} else if (hours === 12) { | ||
currTime = "pm"; | ||
} else if (hours > 12) { | ||
HoursModefied = hours - 12; | ||
currTime = "pm"; | ||
} | ||
return `${time} am`; | ||
|
||
const formattedHour = HoursModefied < 10 ? "0" + HoursModefied : HoursModefied.toString(); | ||
|
||
return `${formattedHour}:${minutes} ${currTime}`; | ||
|
||
} | ||
|
||
const currentOutput = formatAs12HourClock("08:00"); | ||
|
@@ -23,3 +36,32 @@ console.assert( | |
currentOutput2 === targetOutput2, | ||
`current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
); | ||
|
||
const currentOutput3 = formatAs12HourClock("01:00"); | ||
const targetOutput3 = "01:00 am"; | ||
console.assert( | ||
currentOutput3 === targetOutput3, | ||
`current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
); | ||
|
||
const currentOutput4 = formatAs12HourClock("14:00"); | ||
const targetOutput4 = "02:00 pm"; | ||
console.assert( | ||
currentOutput4 === targetOutput4, | ||
`current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
); | ||
|
||
const currentOutput5 = formatAs12HourClock("18:00"); | ||
const targetOutput5 = "06:00 pm"; | ||
console.assert( | ||
currentOutput5 === targetOutput5, | ||
`current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
); | ||
|
||
const currentOutput6 = formatAs12HourClock("00:00"); | ||
const targetOutput6 = "12:00 am"; | ||
console.assert( | ||
currentOutput6 === targetOutput6, | ||
`current output: ${currentOutput6}, target output: ${targetOutput6}` | ||
); | ||
|
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.