Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// interpret the error message and figure out why an error is occurring

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}

Expand Down
7 changes: 3 additions & 4 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);
const result = convertToPercentage(0.5);
console.log(result);

// =============> write your explanation here

Expand Down
5 changes: 4 additions & 1 deletion Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

// =============> write your prediction of the error here

function square(3) {
function square(num) {
return num * num;
}
const result = square(3)
console.log(result);


// =============> write the error message here

Expand Down
2 changes: 1 addition & 1 deletion Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// =============> write your prediction here

function multiply(a, b) {
console.log(a * b);
return a * b ;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
Expand Down
3 changes: 1 addition & 2 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// =============> write your prediction here

function sum(a, b) {
return;
a + b;
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
Expand Down
4 changes: 2 additions & 2 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
function getLastDigit(numbertoconvert) {
return numbertoconvert.toString().slice(-1);
}

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
Expand Down
7 changes: 6 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
const bmi = weight / (height * height);
return Number(bmi.toFixed(1));
// return the BMI of someone based off their weight and height
}
}

console.log(calculateBMI(70, 1.73));
console.log(calculateBMI(85, 1.80));
8 changes: 8 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@
// You will need to come up with an appropriate name for the function
// Use the MDN string documentation to help you find a solution
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
function toUpperSnakeCase(str){
let wordWithUnderscores = str.replaceAll(" ", "_");

let finalResult = wordWithUnderscores.toUpperCase();
return finalResult;
}
console.log(toUpperSnakeCase("hello there"));
console.log(toUpperSnakeCase("lord of the rings"));
29 changes: 29 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,32 @@
// You will need to declare a function called toPounds with an appropriately named parameter.

// You should call this function a number of times to check it works for different inputs

function toPounds(penceString) {

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);


const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");


const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);


const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2);


return `£${pounds}.${pence}`;
}


console.log(toPounds("399p"));
console.log(toPounds("50p"));
console.log(toPounds("1005p"));
console.log(toPounds("1p"));
11 changes: 6 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> 3 times .In the last line of the formatTimeDisplay function, you can see the word pad written three 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
// =============> 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> 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
// =============> 1 The last time the program calls pad, it is looking for the remainingSeconds. When you have 61 seconds, 60 of them make a full minute, and you have 1 second left over. That leftover 1 is what gets sent to num

//
// 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
// =============> 01 .The function takes the number 1. Because the code says padStart(2, "0"), it says: "Hey, this needs to be 2 characters long!". So, it puts a 0 in front of the 1, making it "01".
44 changes: 28 additions & 16 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
const minute = time.slice(3, 5);

let period = "am";
let displayHours = hours;

if (hours === 12) {
period = "pm";
} else if (hours > 12) {
displayHours = hours - 12;
period = "pm";
} else if (hours === 0) {
// 3. Handle Midnight
displayHours = 12;
}
return `${time} am`;


const formattedHours = displayHours.toString().padStart(2, "0");

return `${formattedHours}:${minutes} ${period}`;
}

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);

const currentOutput2 = formatAs12HourClock("23:00");
const targetOutput2 = "11:00 pm";
console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

console.assert(formatAs12HourClock("08:30") === "08:30 am", "Error at 08:30");

console.assert(formatAs12HourClock("23:45") === "11:45 pm", "Error at 23:45");

console.assert(formatAs12HourClock("12:00") === "12:00 pm", "Error at 12:00");

console.assert(formatAs12HourClock("00:15") === "12:15 am", "Error at 00:15");

console.log("If you see no error messages above, all tests passed!");