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
10 changes: 10 additions & 0 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ function capitalise(str) {
}

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

// Your need to delete "let ". That's just for making a new variables. You want assignment.

// =============> write your new code here

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

console.log(capitalise("hello"));
9 changes: 9 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ console.log(decimalNumber);

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

// You need to pass the value in, not declare it within the function. The syntax is wrong.

// Finally, correct the code to fix the problem
// =============> write your new code here

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

}
console.log(convertToPercentage(0.5));
10 changes: 10 additions & 0 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@

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

// num is not defined

function square(3) {
return num * num;
}

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

// SyntaxError: Unexpected token (1:16)

// =============> explain this error message here

// You can't feed the value in there. You need to call it from outside the function. JS thinks it's a variable name which isn't allowed to start with a number.

// Finally, correct the code to fix the problem

// =============> write your new code here

function square(num) {
return num * num;
}

console.log(square(2))
10 changes: 10 additions & 0 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// =============> write your prediction here

// The result of multiplying 10 and 32 is undefined

function multiply(a, b) {
console.log(a * b);
}
Expand All @@ -10,5 +12,13 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

// Nothing is returned in the function but rather logged to the console

// Finally, correct the code to fix the problem
// =============> write your new code here

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

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
11 changes: 11 additions & 0 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Predict and explain first...
// =============> write your prediction here

// It returns blank since it doesn't know what it's returning

function sum(a, b) {
return;
a + b;
Expand All @@ -9,5 +11,14 @@ function sum(a, b) {
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

return a + b is supposed to be on one line. "return;" just returns nothing

// Finally, correct the code to fix the problem
// =============> write your new code here

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

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
12 changes: 12 additions & 0 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Predict the output of the following code:
// =============> Write your prediction here

// It's putting the answer to everything as 3, the last digit of the contant.

const num = 103;

function getLastDigit() {
Expand All @@ -15,10 +17,20 @@ 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

// My prediction was correct.

// Explain why the output is the way it is
// =============> write your explanation here

// function getLastDigit() should have "theNumber" or something in its brackets. It's getting the last digit of the constant as the answer to everything at the moment.

// Finally, correct the code to fix the problem
// =============> write your new code here

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

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
43 changes: 30 additions & 13 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
// Below are the steps for how BMI is calculated
// In Sprint-1, there is a program written in interpret/to-pounds.js

// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.
// You will need to take this code and turn it into a reusable block of code.
// You will need to declare a function called toPounds with an appropriately named parameter.

// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by:
// You should call this function a number of times to check it works for different inputs

// squaring your height: 1.73 x 1.73 = 2.99
// dividing 70 by 2.99 = 23.41
// Your result will be displayed to 1 decimal place, for example 23.4.
function calculateBMI(penceString) {

// You will need to implement a function that calculates the BMI of someone based off their weight and height
// remove last character
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

// Given someone's weight in kg and height in metres
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place
// pad to the length of three
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
// remove the last two characters
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

// get last two characters and pad to two if needed
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

console.log(`£${pounds}.${pence}`);

}

console.log(calculateBMI("456p"))
console.log(calculateBMI("545747p"))
console.log(calculateBMI("1p"))
6 changes: 6 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,9 @@
// 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 snakeCase(toConvert) {
return toConvert.replace(" ", "_").toUpperCase();
}

console.log(snakeCase("hello there"));
30 changes: 30 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,33 @@
// 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 calculateBMI(penceString) {

// remove last character
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

// pad to the length of three
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

// remove the last two characters
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

// get last two characters and pad to two if needed
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

console.log(`£${pounds}.${pence}`);

}

console.log(calculateBMI("456p"))
console.log(calculateBMI("545747p"))
console.log(calculateBMI("1p"))
10 changes: 5 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ function formatTimeDisplay(seconds) {
// Questions

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

// 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 - Remaining seconds is calculated first with %60 and 1 is what's left over.

// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> "01" - now it's padded to 2 digits
Loading