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
9 changes: 7 additions & 2 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Predict and explain first...
// =============> write your prediction here
// =============> Prediction: The function capitalise is possibly meant to capitalise the first letter in a string.

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
Expand All @@ -9,5 +9,10 @@ function capitalise(str) {
return str;
}

// =============> write your explanation here
// =============> =============> write your explanation here
// The 'str' variable on the left hand side is the same used in the function name implementation which should not be.
// =============> write your new code here
function capitalise(str) {
let capFunction = `${str[0].toUpperCase()}${str.slice(1)}`;
return capFunction;
}
9 changes: 6 additions & 3 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> I suspect than an error will occur

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

Expand All @@ -14,7 +14,10 @@ function convertToPercentage(decimalNumber) {

console.log(decimalNumber);

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

// =============> write your explanation here. The functions takes a decimal number as input and converts it to percentage by multiplying by 100
// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
12 changes: 8 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
// =============> write your prediction of the error here. The error is likely to be caused by square(3), '3' is supposed to be replaced by a string representing the number.

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

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

// function square(3) {
// ^
// SyntaxError: Unexpected number
// =============> explain this error message here

// The muber '3' should be used when calling the function and it should not be used as a parameter.
// Finally, correct the code to fix the problem

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

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

7 changes: 5 additions & 2 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Predict and explain first...

// =============> write your prediction here
// =============> write your prediction here. It may likely have issues as console.log() is within function implementation, instead of using'return'

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

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here
// =============> write your explanation here. Instead of having console.log() is within function implementation, it should be replaced with 'return'

// Finally, correct the code to fix the problem
// =============> write your new code here
function multiply(a, b) {
return (a * b);
}
8 changes: 6 additions & 2 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Predict and explain first...
// =============> write your prediction here
// =============> write your prediction here. An error will result becasue of the ';' between return and a + b


function sum(a, b) {
return;
Expand All @@ -8,6 +9,9 @@ function sum(a, b) {

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// =============> write your explanation here. The ideal statement should be 'return a + b; ' but this statement is separated by ';'
// Finally, correct the code to fix the problem
// =============> write your new code here
function sum(a, b) {
return a + b;
}
16 changes: 13 additions & 3 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> Write your prediction here. It may run but give incorrect results because of const num & no parameter specified


const num = 103;

Expand All @@ -15,10 +16,19 @@ 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
// 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
// =============> write your explanation here. num is a constant variable, it's value cannot change.
// Finally, correct the code to fix the problem
// =============> write your new code here

function getLastDigit() {
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
// getLastDigit is not working properly because the value for num is fixed at '103'
function getLastDigit(num) {
return num.toString().slice(-1);
}
1 change: 1 addition & 0 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
return Math.round((weight) / (height ** 2)).toFixed(1)
}
4 changes: 4 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,7 @@
// 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 upCase(strCar) {
let result = strCar.toUpperCase().replaceAll(" ", "_");
return result;
}
20 changes: 20 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,23 @@
// 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(money) {
const moneyWithoutTrailingP = money.substring(
0,
money.length - 1
);
const paddedPenceNumberString = moneyWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
result = pounds + "." + pence;
res = `£${pounds}.${pence}`;
return res;
}
console.log(toPounds("399p"))
console.log(toPounds("1099p"))
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 @@ -17,18 +17,18 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> write your answer here.pad will be called 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
// =============> write your answer here. the value assigned to num when pad is called for the first time is 00

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> write your answer here. the return value of pad is called for the first time is '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
// =============> write your answer here. the value assigned to num when pad is called for the last time is 01

// 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. the return value assigned to num when pad is called for the last time in this program is '01'