diff --git a/Sprint-1/Module-Structuring-and-Testing-Data b/Sprint-1/Module-Structuring-and-Testing-Data new file mode 160000 index 0000000000..3372770a4d --- /dev/null +++ b/Sprint-1/Module-Structuring-and-Testing-Data @@ -0,0 +1 @@ +Subproject commit 3372770a4d6ae71b931968a6d6deb70dda58a065 diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..0f61b1945d 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -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); +// } +// //} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..998519eaab 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -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 @@ -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)); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..4c4e19e524 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -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; +// } diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..d73107f5d4 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // 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); @@ -8,7 +8,10 @@ function multiply(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; +//} \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..51b05128fc 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -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; @@ -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; +//} \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..76cbdf2520 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -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; @@ -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. diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..1325f80a8e 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -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); } \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..9ecc8e6863 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -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("_"); +} diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..ca6385c1ad 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -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")); \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 15d5798054..318d0d3b10 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -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"