Skip to content

Commit ff97d70

Browse files
coursework update
1 parent 7dec005 commit ff97d70

4 files changed

Lines changed: 44 additions & 5 deletions

File tree

Sprint-2/1-key-errors/0.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function capitalise(str) {
88
return str;
99
}
1010

11-
// he error message says 'str' has already been declared so we can use another name for our
11+
// Te error message says 'str' has already been declared so we can use another name for our
1212
//output to solve that error we change the output variable name
1313
// function capitalise(str) {
1414
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
// Then when we call this function with the weight and height
1515
// It should return their Body Mass Index to 1 decimal place
1616

17-
function calculateBMI(weight, height) {
18-
let bmi = weight / height*height;
19-
return bmi;
17+
function calculateBMI(weight,height) {
18+
return (weight/(height*height)).toFixed(1);
19+
2020
// return the BMI of someone based off their weight and height
2121
}
22-
console.log(`Your BMI is ${bmi}`)
22+
console.log(`Your BMI is ${calculateBMI(56,1.5)}`)
23+
//console.log(`Your BMI is ${calculateBMI(weight,height)}`)

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@
1414
// You will need to come up with an appropriate name for the function
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17+
function caseToUpperS(string){
18+
return string.toUpperCase().replaceAll(" ", "_");
19+
20+
}
21+
console.log(`Your new word is ${caseToUpperS("i love cyf so much")}`)

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,36 @@
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

66
// You should call this function a number of times to check it works for different inputs
7+
function toPounds(penceString){
8+
9+
let penceStringWithoutTrailingP = penceString.substring(
10+
0,
11+
penceString.length - 1
12+
);
13+
14+
let paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15+
let pounds = paddedPenceNumberString.substring(
16+
0,
17+
paddedPenceNumberString.length - 2
18+
);
19+
20+
let pence = paddedPenceNumberString
21+
.substring(paddedPenceNumberString.length - 2)
22+
.padEnd(2, "0");
23+
24+
return {pounds, pence};
25+
}
26+
const { pounds, pence } = toPounds("10390p");
27+
28+
console.log(${pounds}.${pence}`);
29+
30+
31+
32+
// This program takes a string representing a price in pence
33+
// The program then builds up a string representing the price in pounds
34+
35+
// You need to do a step-by-step breakdown of each line in this program
36+
// Try and describe the purpose / rationale behind each step
37+
38+
// To begin, we can start with
39+
// 1. const penceString = "399p": initialises a string variable with the value "399p"

0 commit comments

Comments
 (0)