Skip to content

Commit 68a38ee

Browse files
author
Arthur
committed
These commits belong to acoursework sprint 2 branch
Merge branch 'acoursework/sprint-1-' into acoursework/sprint-2
2 parents 2710dcd + f3fb08d commit 68a38ee

3 files changed

Lines changed: 58 additions & 15 deletions

File tree

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@ console.log(`£${pounds}.${pence}`);
2323
// You need to do a step-by-step breakdown of each line in this program
2424
// Try and describe the purpose / rationale behind each step
2525

26-
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"

Sprint-2/3-mandatory-implement/3-to-pounds.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,30 @@
33
// You will need to take this code and turn it into a reusable block of code.
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

6-
// You should call this function a number of times to check it works for different inputs
6+
function toPounds(penceString){
7+
8+
const penceStringWithoutTrailingP = penceString.substring(
9+
0,
10+
penceString.length - 1
11+
);
12+
13+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
14+
const pounds = paddedPenceNumberString.substring(
15+
0,
16+
paddedPenceNumberString.length - 2
17+
);
18+
19+
const pence = paddedPenceNumberString
20+
.substring(paddedPenceNumberString.length - 2)
21+
.padEnd(2, "0");
22+
23+
return ${pounds}.${pence}`;
24+
25+
}
26+
27+
console.log(toPounds("499p"));
28+
console.log(toPounds("399p"));
29+
console.log(toPounds("299p"));
30+
31+
32+
// You should call this function a number of times to check it works for different inputs

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,43 @@ function formatTimeDisplay(seconds) {
1515
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1616
}
1717

18+
1819
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1920
// to help you answer these questions
2021

21-
// Questions
22+
console.log(formatTimeDisplay(61));
23+
24+
25+
26+
27+
28+
Questions
29+
30+
a) When formatTimeDisplay is called how many times will pad be called?
31+
3 time.
32+
33+
34+
b) What is the value assigned to num when pad is called for the first time?
35+
=============> parameter
36+
37+
38+
39+
c) What is the return value of pad is called for the first time?
40+
=============> numString variable
41+
42+
43+
44+
d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
45+
=============>
46+
2247

23-
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
2548

26-
// Call formatTimeDisplay with an input of 61, now answer the following:
49+
e) What is the return value of pad when it is called for the last time in this program?
2750

28-
// b) What is the value assigned to num when pad is called for the first time?
29-
// =============> write your answer here
3051

31-
// c) What is the return value of pad is called for the first time?
32-
// =============> write your answer here
52+
The three functions of pad are called
53+
in three variables totalMinutes, remainingMinutes and totalHours.
54+
The last variable in the pad function is called remainingSeconds;
3355

34-
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
35-
// =============> write your answer here
3656

37-
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
38-
// =============> write your answer here
57+
// =============>

0 commit comments

Comments
 (0)