From 7dec0051e91443b2a9630aa0093a0aff78c595fb Mon Sep 17 00:00:00 2001 From: risikatpopoola Date: Mon, 29 Jun 2026 11:56:15 +0100 Subject: [PATCH 1/2] coursework --- Sprint-2/1-key-errors/0.js | 13 ++++++++----- Sprint-2/1-key-errors/1.js | 18 +++++++++++++----- Sprint-2/1-key-errors/2.js | 9 +++++++-- Sprint-2/2-mandatory-debug/0.js | 8 +++++++- Sprint-2/2-mandatory-debug/1.js | 7 +++++++ Sprint-2/2-mandatory-debug/2.js | 18 ++++++++++++++---- Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++++- 7 files changed, 60 insertions(+), 18 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..1b7f52a87e 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,7 +1,6 @@ // Predict and explain first... -// =============> write your prediction here - -// call the function capitalise with a string input +// =============> We use a string template when we want to join different character sets together but by casing the first letter +// to uppercase we're assuming that it is formed of letters // interpret the error message and figure out why an error is occurring function capitalise(str) { @@ -9,5 +8,9 @@ function capitalise(str) { return str; } -// =============> write your explanation here -// =============> write your new code here +// he error message says 'str' has already been declared so we can use another name for our +//output to solve that error we change the output variable name +// function capitalise(str) { + // let str = `${str[0].toUpperCase()}${str.slice(1)}`; + // return str; +//} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..6af13343fb 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,8 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// The parameter is a constant which means the program will output the same thing everytime, +//and would give an error message saying it has been declared if run. // Try playing computer with the example to work out what is going on @@ -10,11 +11,18 @@ function convertToPercentage(decimalNumber) { const percentage = `${decimalNumber * 100}%`; return percentage; + + console.log(decimalNumber); } +// =============> Our parameter has already been declared which is why the program is resulting in an error -console.log(decimalNumber); +// Finally, correct the code to fix the problem +// function convertToPercentage(decimalNumber) { + // const decimalNumber1 = 0.5; + //const percentage = `${decimalNumber1 * 100}%`; -// =============> write your explanation here + // return percentage; + // console.log(decimalNumber1); +//} -// Finally, correct the code to fix the problem -// =============> write your new code here +// diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..db9bc0146c 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,25 @@ // Predict and explain first BEFORE you run any code... - +//We are going to get an error because an integer cannot be a parameter, it has to be a variable. // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +//syntaxERror, identifier cannot be an integer function square(3) { return num * num; } // =============> write the error message here +// Uncaught SyntaxError SyntaxError: Unexpected number // =============> explain this error message here - +//The program was expecting a function parameter but got a number instead // Finally, correct the code to fix the problem // =============> 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..4d176b63db 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,7 +1,8 @@ // Predict and explain first... // =============> write your prediction here - +//This won't work because we are not returning anything. + function multiply(a, b) { console.log(a * b); } @@ -11,4 +12,9 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here // Finally, correct the code to fix the problem +//function multiply(a, b) { +//return a * b; +//} + +//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..0bdad8a905 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +//This won't work because of a syntax error, return a+b should be on a single line and not on separate lines function sum(a, b) { return; @@ -9,5 +10,11 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The sum of a + b is undefined because we are not returning any value // 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)}`); \ 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..9fc1bbfe1e 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,8 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> Write your prediction +//It should output string cannot be accessed because we are using normal brackets instead of square brackets const num = 103; @@ -14,11 +15,20 @@ 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 +// =============>The output was 3 for all instead of the last digit of each number. +// // Explain why the output is the way it is -// =============> write your explanation here +// =============> This is because we already declared the num variable as a constant // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> 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 +//There was no parameter so the function wasn't running properly. +//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)}`); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..c7710d2bb6 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + let bmi = weight / height*height; + return bmi; // return the BMI of someone based off their weight and height -} \ No newline at end of file +} +console.log(`Your BMI is ${bmi}`) \ No newline at end of file From ff97d708ea101257a415be816319e92f16fd2c35 Mon Sep 17 00:00:00 2001 From: risikatpopoola Date: Wed, 1 Jul 2026 12:00:05 +0100 Subject: [PATCH 2/2] coursework update --- Sprint-2/1-key-errors/0.js | 2 +- Sprint-2/3-mandatory-implement/1-bmi.js | 9 ++--- Sprint-2/3-mandatory-implement/2-cases.js | 5 +++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 33 +++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 1b7f52a87e..e858e31951 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -8,7 +8,7 @@ function capitalise(str) { return str; } -// he error message says 'str' has already been declared so we can use another name for our +// Te error message says 'str' has already been declared so we can use another name for our //output to solve that error we change the output variable name // function capitalise(str) { // let str = `${str[0].toUpperCase()}${str.slice(1)}`; diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index c7710d2bb6..e5fc551787 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,9 +14,10 @@ // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place -function calculateBMI(weight, height) { - let bmi = weight / height*height; - return bmi; +function calculateBMI(weight,height) { + return (weight/(height*height)).toFixed(1); + // return the BMI of someone based off their weight and height } -console.log(`Your BMI is ${bmi}`) \ No newline at end of file +console.log(`Your BMI is ${calculateBMI(56,1.5)}`) +//console.log(`Your BMI is ${calculateBMI(weight,height)}`) \ 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..c4ab2605c3 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,8 @@ // 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 caseToUpperS(string){ + return string.toUpperCase().replaceAll(" ", "_"); + +} +console.log(`Your new word is ${caseToUpperS("i love cyf so much")}`) \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..cda838ae5a 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,36 @@ // 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){ + + let penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + + let paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + let pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + + let pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + return {pounds, pence}; +} +const { pounds, pence } = toPounds("10390p"); + +console.log(`£${pounds}.${pence}`); + + + +// This program takes a string representing a price in pence +// The program then builds up a string representing the price in pounds + +// You need to do a step-by-step breakdown of each line in this program +// Try and describe the purpose / rationale behind each step + +// To begin, we can start with +// 1. const penceString = "399p": initialises a string variable with the value "399p"