diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..bc1478768 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,20 +1,27 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here - +// =============> write your prediction here decimalNumber has already been declared in the function. const can not redeclare a variable with the same name in the same scope. parameter, so we cannot declare it again with const. +// This will cause a syntax error. To fix this, we should remove the const keyword when assigning the new value to decimalNumber. +// console.log(decimalNumber); only exists inside the function. // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +//function convertToPercentage(decimalNumber) { +//const decimalNumber = 0.5; +//const percentage = `${decimalNumber * 100}%`; - return percentage; -} +//return percentage; +//} -console.log(decimalNumber); +//console.log(decimalNumber); // =============> write your explanation here // 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)); diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..05966cbf8 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,21 @@ - -// Predict and explain first BEFORE you run any code... +// SyntaxError: Unexpected token '3' // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here -function square(3) { - return num * num; -} - -// =============> write the error message here +//function square(3) { +// return num * num; +//} +// =============> write the error message here SyntaxError: Unexpected token (1:16) // =============> explain this error message here // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)); diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..d9bead1d7 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,21 @@ -// Predict and explain first... +// Predict and explain first...didn't declare the a and b parameters in the function. This will cause a ReferenceError. To fix this, we should declare the parameters a and b in the function definition. -// =============> write your prediction here +// =============> write your prediction here function doesn't return anything, so the result of multiplying 10 and 32 is undefined. +// To fix this, we should add a return statement to the function to return the result of multiplying a and b. -function multiply(a, b) { - console.log(a * b); -} +//function multiply(a, b) { -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +//console.log(a * b); +//} + +//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> The result of multiplying 10 and 32 is undefined'write your explanation here // 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)}`); diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..e6034d6b5 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,19 @@ -// Predict and explain first... -// =============> write your prediction here +// Predict and explain first... function doesn't return anything, so the result of multiplying 10 and 32 is undefined. +// To fix this, we should add a return statement to the function to return the result of multiplying a and b. +// =============> write your prediction here 'The sum of 10 and 32 is undefined' -function sum(a, b) { - return; - a + b; -} +//function sum(a, b) { +//return; +//a + b; +//} -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here // 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)}`); diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..4fb2bba86 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -1,24 +1,36 @@ -// Predict and explain first... +// Predict and explain first...const num is declared outside the function, so it is not accessible inside the function. This will cause a ReferenceError. +// To fix this, we should pass the number as a parameter to the function and use that parameter inside the function. // Predict the output of the following code: -// =============> Write your prediction here +// =============> Write your prediction here 3,3,3 -const num = 103; +//const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +//function getLastDigit() { +//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)}`); +//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)}`); // Now run the code and compare the output to your prediction -// =============> write the output here +// =============> 2,5,6 // Explain why the output is the way it is -// =============> write your explanation here +// =============> the output is the way function is called with an argument, so the function is able to access the value of the argument passed to it and return the last digit of that number. +// The function is not using the variable num declared outside the function, so it does not cause a ReferenceError. // Finally, correct the code to fix the problem // =============> write your new code here // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem + +const num = 103; + +function getLastDigit(n) { + return n.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)}`); diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..a6d904835 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -6,14 +6,17 @@ // 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'. +// Your result will be displayed to 1 decimal place, for example 23.4. // You will need to implement a function that calculates the BMI of someone based off their weight and height // Given someone's weight in kg and height in metres // Then when we call this function with the weight and height -// It should return a string of their Body Mass Index to 1 decimal place +// It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + return (weight / (height * height)).toFixed(1); } +console.log(calculateBMI(90, 1.7)); +// return the BMI of someone based off their weight and height +// return the BMI of someone based off their weight and height diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..0258f93e9 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // 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 convertToUpperSnakeCase(inputString) { + const captializedInputString = inputString.toUpperCase(); + const withUnderScore = captializedInputString.split(" ").join("_"); + return withUnderScore; +} + +console.log(convertToUpperSnakeCase("Hello there")); diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..7e59a95d8 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -1,6 +1,30 @@ -// In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js +// In Sprint-1, there is a program written in interpret/to-pounds.js // 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. // 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("99p")); // £0.99 +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("123p")); // £1.23 diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..8225ddfb1 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -14,6 +14,7 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)); // 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 @@ -21,18 +22,22 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> pad will be called 3 times, once for each of the hours, minutes, and seconds values that are being formatted into a string. // 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 +// =============>Pad is called for the first time with the value of 0, which is the total hours calculated from the input of 61 seconds. +// The total hours is calculated by dividing the total minutes (1) by 60, which results in 0 hours. pad(totalHours) -// c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// c) What is the return value of pad is called for the first time? +// =============> 0 is the value assigned to num when pad is called for the first time, and the return value of pad is "00". This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2. Since num is 0, it becomes "00" after one iteration of the loop. // 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 +// =============> pad(remainingSeconds) remainingSeconds =1, so num is +1. This is because the input to formatTimeDisplay is 61 seconds, which results in 1 second remaining after calculating the total minutes and hours. The pad function is called with this value to format it as a two-digit string for display. // 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 +// =============> numString = "1" so string has only one character "01" the return value of pad when it is called for the last time in this program is "01". +// This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2. +// Since num is 1, it becomes "01" after one iteration of the loop. +// diff --git a/Wireframe/README.md b/Wireframe/README.md deleted file mode 100644 index b1712c4b3..000000000 --- a/Wireframe/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# Wireframe - -## Learning Objectives - - - -- [ ] Use semantic HTML tags to structure the webpage -- [ ] Create three articles, each including an image, title, summary, and a link -- [ ] Use CSS to lay out and style elements so they match a wireframe design -- [ ] Test web code using [Lighthouse](https://programming.codeyourfuture.io/guides/testing/lighthouse) -- [ ] Use version control by committing often and pushing regularly to GitHub -- [ ] Develop the habit of writing clean, well-structured, and error-free code - - -## Task -![Wireframe](./wireframe.png) - -Using the provided wireframe and resources, write a new webpage explaining: - -1. What is the purpose of a README file? -1. What is the purpose of a wireframe? -1. What is a branch in Git? - -Then arrange and style the elements so the page closely matches the wireframe. Exact replication is the goal, but small differences may be accepted. - -You can add image files, but you _must_ modify `index.html` and `style.css` to meet the acceptance criteria and you must check this criteria yourself before you submit your work. - -## Acceptance Criteria - -- [ ] Semantic HTML tags are used to structure the webpage. -- [ ] The page scores 100 for Accessibility in the Lighthouse audit. -- [ ] The webpage is styled using a linked .css file. -- [ ] The webpage is properly committed and pushed to a branch on GitHub. -- [ ] The articles section contains three distinct articles, each with its own unique image, title, summary, and link. -- [ ] The page footer is fixed to the bottom of the viewport; it remains in place when the page scrolls. -- [ ] The page layout closely match the wireframe. - -### Developers must adhere to professional standards. - -> Before you say you're done: Is your code readable? Does it run correctly? Does it look professional? - -These practices reflect the level of quality expected in professional work. -They ensure your code is reliable, maintainable, and presents a polished, credible experience to users. - -- [ ] My HTML code has no errors or warnings when validated using https://validator.w3.org/ -- [ ] My code is consistently formatted -- [ ] My page content is free of typos and grammatical mistakes -- [ ] I commit often and push regularly to GitHub - -## Resources - -- [Wireframe](https://www.productplan.com/glossary/wireframe/) -- [Semantic HTML](https://www.w3schools.com/html/html5_semantic_elements.asp) -- [:first-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child) -- [Format Code and Make Logical Commits in VS Code](../practical_guide.md)