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
1 change: 1 addition & 0 deletions Sprint-1/Module-Structuring-and-Testing-Data
Submodule Module-Structuring-and-Testing-Data added at 337277
10 changes: 7 additions & 3 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Predict and explain first...
// =============> write your prediction here
// =============> The error will be that the variable str is being redefined within the function. It was already defined when it was passed as an arguement.

// call the function capitalise with a string input
capitalise("hello world");
// interpret the error message and figure out why an error is occurring
// Error message: SyntaxError: Identifier 'str' has already been declared. The error is because the variable str has already been declared.

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

// =============> write your explanation here
// =============> write your new code here
// //function capitalise(str) {
// return str[0].toUpperCase() + str.slice(1);
// }
// //}
11 changes: 8 additions & 3 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> The error will be a syntax error because the variable decimalNumber has already been declared as a parameter. The console log is trying to access decimalNumber which is not within its scope.

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

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

console.log(decimalNumber);

// =============> write your explanation here
// =============> I got a syntax error that the variable is already declared.

// 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));
15 changes: 7 additions & 8 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

// Predict and explain first BEFORE you run any code...

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

// =============> write your prediction of the error here
// =============> The error will be a syntax error. A number is not a valid variable name - variable names cannot start with a number.

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

// =============> write the error message here
// =============> write the error message here: SyntaxError: Unexpected number. The error is because the variable name cannot start with a number.

// =============> explain this error message here
// =============> explain this error message here: You cannot begin a variable name with a number

// Finally, correct the code to fix the problem

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


// =============> 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: The function does not return any value so instead of 320 being printed, undefined will be printed instead.

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: It is a logic error as it prints out an unexpected value, undefined.

// Finally, correct the code to fix the problem
// =============> write your new code here
//function multiply(a, b) {
// return a * b;
//}
7 changes: 5 additions & 2 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Predict and explain first...
// =============> write your prediction here
// =============> write your prediction here: The function does not return any value. The a + b should be before the semi-colon and after the return. It will print undefined instead of 42.

function sum(a, b) {
return;
Expand All @@ -8,6 +8,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: It is a logic error as it prints out an unexpected answer, undefined.
// Finally, correct the code to fix the problem
// =============> write your new code here
// function sum(a, b) {
// return a + b;
//}
16 changes: 12 additions & 4 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> Write your prediction here: The function getLastDigit doesn't take any parameters, so it will always return the last digit of the number 103, 3.

const num = 103;

Expand All @@ -14,11 +14,19 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
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
// =============> 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: The function getLastDigit doesn't take any parameters, so it always returns the last digit of the variable num, which is 103.
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============> write your new code here:
// function getLastDigit(num) {
// return num.toString().slice(-1);
// }

// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
// The function getLastDigit is not working properly because it does not take any parameters, so it always returns the last digit of the variable num, which is 103.
2 changes: 2 additions & 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,6 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
const bmi = weight / (height * height);
return bmi.toFixed(1);
}
Comment on lines 17 to 21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to write the code to make it more readable? Also, look into the bmi calculation to make sure the right calculation is done within your code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment! I've updated the code

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 upperSnakeCase(str){
return str.toUpperCase().split(" ").join("_");
}
Comment on lines +18 to +20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good way to handle some edge cases from the passed argument

11 changes: 11 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,14 @@
// 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).padEnd(2, "0");
return `£${pounds}.${pence}`;
}

console.log(toPounds("100p"));
console.log(toPounds("30000p"));
19 changes: 8 additions & 11 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ function formatTimeDisplay(seconds) {
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}

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

// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> 3 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
// c) What is the return value of pad when it is called for the first time?
// =============> "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
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> 1. The last pad call is pad(remainingSeconds), and with 61 seconds input, remainingSeconds = 61 % 60 = 1

// 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
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> "01". pad(1) calls toString() to get "1", then padStart(2, "0") pads it to "01"
Loading