-
-
Notifications
You must be signed in to change notification settings - Fork 116
ITP_GLASGOW_MAR | HANNA_MYKYTIUK | MODULE_STRUCTURING_AND_TESTING_DATA | SPRINT_2 #441
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 5 commits
f4e9c6b
6c4cfde
980fac0
3ee1a41
eba5d0c
5de2a8e
06bd8cf
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,8 +1,8 @@ | ||
// Predict and explain first... | ||
|
||
// the code won't work | ||
// Why will an error occur when this program runs? | ||
// =============> write your prediction here | ||
|
||
// because of variable decimaNumber is already declared. And out of range of conlole function | ||
// Try playing computer with the example to work out what is going on | ||
|
||
function convertToPercentage(decimalNumber) { | ||
|
@@ -18,3 +18,13 @@ console.log(decimalNumber); | |
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
|
||
function convertToPercentage(decimalNumber) { | ||
decimalNumber = 0.5; | ||
const percentage = `${decimalNumber * 100}%`; | ||
|
||
console.log(decimalNumber); | ||
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 think the function is expected to compute and return a percentage string when given a number; it should not output If we want to output 0.25 as 25%, we could write |
||
return percentage; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
// Predict and explain first... | ||
|
||
//it won't work | ||
// Predict the output of the following code: | ||
// =============> Write your prediction here | ||
// I've just checked | ||
//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 | ||
// =============> write the output here | ||
// The last digit of 42 is 3 | ||
// The last digit of 105 is 3 | ||
// The last digit of 806 is 3 | ||
// Explain why the output is the way it is | ||
// =============> write your explanation here | ||
// because of const 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. | ||
|
||
|
||
|
||
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)}`); | ||
|
||
// Explain why getLastDigit is not working properly - correct the problem | ||
//function getLastDigit(num) - should be like that |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,9 @@ | |
// It should return their Body Mass Index to 1 decimal place | ||
|
||
function calculateBMI(weight, height) { | ||
let BMI = weight/(height*height); | ||
return BMI.toFixed(1); | ||
|
||
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. What type of value do you think the function should return? A number or a string? |
||
// return the BMI of someone based off their weight and height | ||
} | ||
} | ||
console.log(calculateBMI(62.99,1.64)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,24 +11,25 @@ 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 | ||
// =============> write your answer here: tree 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 | ||
// =============> write your answer here: 00:01:01 | ||
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 think you misread the question. That's not the value assigned to |
||
|
||
// c) What is the return value of pad is called for the first time? | ||
// =============> write your answer here | ||
// =============> write your answer here: '00' - string of full hours | ||
|
||
// 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 | ||
// =============> write your answer here: 1 - Number of seconds remainder | ||
|
||
// 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 | ||
// =============> write your answer here: '01' - String of seconds remainder |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ | |
|
||
function formatAs12HourClock(time) { | ||
const hours = Number(time.slice(0, 2)); | ||
const minutes = time.slice(-2); | ||
if (hours > 12) { | ||
return `${hours - 12}:00 pm`; | ||
return `${hours - 12}:${minutes} pm`; | ||
} | ||
return `${time} am`; | ||
} | ||
|
@@ -23,3 +24,36 @@ console.assert( | |
currentOutput2 === targetOutput2, | ||
`current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
); | ||
|
||
////////////// | ||
// hours > 12 and minutes NOT 00 | ||
const currentOutput3 = formatAs12HourClock("23:45"); | ||
const targetOutput3 = "11:45 pm"; | ||
console.assert( | ||
currentOutput3 === targetOutput3, | ||
`current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
); | ||
|
||
// hours < 12 and minutes NOT 00 | ||
const currentOutput4 = formatAs12HourClock("09:13"); | ||
const targetOutput4 = "09:13 am"; | ||
console.assert( | ||
currentOutput4 === targetOutput4, | ||
`current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
); | ||
|
||
// hours = 00 and minutes = 00 | ||
const currentOutput5 = formatAs12HourClock("00:00"); | ||
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 think "00:00" should be converted to "12:00 am" (midnight). |
||
const targetOutput5 = "00:00 am"; | ||
console.assert( | ||
currentOutput5 === targetOutput5, | ||
`current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
); | ||
|
||
// hours = 12 and minutes = 00 | ||
const currentOutput6 = formatAs12HourClock("12:00"); | ||
const targetOutput6 = "00:00 pm"; | ||
console.assert( | ||
currentOutput5 === targetOutput5, | ||
`current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
); | ||
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 think "12:00" should be converted to "12:00 pm" (noon). |
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.
If we replace the parameter value, how do we expect to convert different numbers using this function?