-
-
Notifications
You must be signed in to change notification settings - Fork 238
Glasgow | 25-ITP-SEP | Mohammed Abdoon | Sprint 2 | Coursework #725
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 9 commits
6959f9a
8472bf4
80d9aff
4ccd588
a6c691a
3edc12c
c8fe831
be15364
5b3cd1e
f3c3be7
fa69127
eb8e26b
f4b2947
3d1b3c8
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,4 +1,5 @@ | ||
node_modules | ||
.DS_Store | ||
.vscode | ||
testing.js --- IGNORE --- | ||
**/.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// The code has a function that is supposed to capitalise the string passed to it. (only the first letter) | ||
// the string will be stored in the variable str and the function will return its value. | ||
// it takes the first letter (str[0]) and uses toUpperCase() method to capitalise it. | ||
// the str.slice(1) method is used to show the letter. | ||
// | ||
|
||
// 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; | ||
} | ||
|
||
// =============> write your explanation here | ||
// an error occured because the variable str was already declared as a parameter of the function so | ||
// there was no need to use let again. | ||
|
||
|
||
// =============> write your new code here | ||
function capitalise(str) { | ||
str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
} | ||
|
||
console.log(capitalise("hello")); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,24 +11,31 @@ function formatTimeDisplay(seconds) { | |
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; | ||
} | ||
|
||
console.log(formatTimeDisplay(61)); | ||
// 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 | ||
// The function pad will be called 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 | ||
// the value is 0 | ||
|
||
// c) What is the return value of pad is called for the first time? | ||
// =============> write your answer here | ||
// # The Python visualizer stops working when it runs pad because (padStart is not a function), maybe because it uses ES6 version of javascript! | ||
// The return value of pad when it's called for the first time 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 | ||
//the value assigned to num is 1 . the value 1 is the number of the remaining seconds, pad() converted it to 01 | ||
|
||
// 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 | ||
// the return value is 01 . the function pad() converted num (which values 1) to 01 so the seconds can be readable easily. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,49 @@ | |
// 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`; | ||
let hours = time.slice(0, 2); | ||
let minutes= time.slice(3, 5); | ||
|
||
if (Number(hours) > 12) { | ||
hours = String(hours - 12); | ||
hours = hours.padStart(2, "0"); | ||
|
||
return `${hours}:${minutes} pm`; | ||
} | ||
return `${time} am`; | ||
return `${hours}:${minutes} am`; | ||
} | ||
|
||
const currentOutput = formatAs12HourClock("08:00"); | ||
const targetOutput = "08:00 am"; | ||
let currentOutput = formatAs12HourClock("14:00"); | ||
let targetOutput = "02:00 pm"; | ||
console.assert( | ||
currentOutput === targetOutput, | ||
`current output: ${currentOutput}, target output: ${targetOutput}` | ||
); | ||
|
||
const currentOutput2 = formatAs12HourClock("23:00"); | ||
const targetOutput2 = "11:00 pm"; | ||
//========================== | ||
currentOutput = formatAs12HourClock("23:00"); | ||
targetOutput = "11:00 pm"; | ||
console.assert( | ||
currentOutput2 === targetOutput2, | ||
`current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
currentOutput === targetOutput, | ||
`current output: ${currentOutput}, target output: ${targetOutput}` | ||
); | ||
//========================== | ||
currentOutput = formatAs12HourClock("07:51"); | ||
targetOutput = "07:51 am"; | ||
console.assert( | ||
currentOutput === targetOutput, | ||
`current output: ${currentOutput}, target output: ${targetOutput}` | ||
); | ||
//========================== | ||
currentOutput = formatAs12HourClock("00:37"); | ||
targetOutput = "00:37 am"; | ||
|
||
console.assert( | ||
currentOutput === targetOutput, | ||
`current output: ${currentOutput}, target output: ${targetOutput}` | ||
); | ||
//========================== | ||
currentOutput = formatAs12HourClock("20:59"); | ||
targetOutput = "08:59 pm"; | ||
console.assert( | ||
currentOutput === targetOutput, | ||
`current output: ${currentOutput}, target output: ${targetOutput}` | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function formatAs12HourClock(time) { | ||
if (Number(time.slice(0, 2)) > 12) | ||
{ | ||
return `${Number(time.slice(0, 2) - 12)}:00 pm`; | ||
} | ||
return `${time} am`; | ||
} | ||
|
||
let targetOutPut = "2:00 pm"; | ||
let currentOutPut= formatAs12HourClock("14:00"); | ||
|
||
console.assert( | ||
targetOutPut === currentOutPut, | ||
`current output: ${currentOutPut}, target output: ${targetOutPut}` | ||
); | ||
// ========= | ||
targetOutPut = "11:00 am"; | ||
currentOutPut= formatAs12HourClock("11:00"); | ||
|
||
console.assert( | ||
currentOutPut === targetOutPut, | ||
`Error,, current is ${currentOutPut} and target is ${targetOutPut}` | ||
); |
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.
Did you notice the variables
squaredHeight
andBMI
are rendered in different colors?Many IDEs and viewers that support syntax highlighting (including GitHub) display identifiers in different formats and colors. Can you find out why?
Can you look up the naming conventions in JavaScript? In particular,
Then, update the variable names according to those conventions.