diff --git a/Sprint-1/errors/2.js b/Sprint-1/errors/2.js index e09b89831..0e52ca5be 100644 --- a/Sprint-1/errors/2.js +++ b/Sprint-1/errors/2.js @@ -1,5 +1,9 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + + +//This is a hosting error. You can't use a variable before declaring it. I have made some changes on how I believe it should be. \ No newline at end of file diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index ec101884d..8532e4027 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -1,5 +1,6 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const cardNumberStrings = cardNumber.toString(); +const last4Digits = cardNumberStrings.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +8,10 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + + +// I believe the the code is correct. However, the first variable is considered as a string. If operation were to be done on it, the output should first be converted into an integer. + +//I used toString method on the cardNumber to turn it into strings and then use slice to retrieve the last 4 digits. + +// I converted the cardNumber integers into a string and assigned them to a variable called cardNumberStrings, this way, I can continue using the 'const' declaration instead of using the 'let' \ No newline at end of file diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 21dad8c5d..a9d065129 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,2 +1,6 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const twenty4HourClockTime = "20:53"; +const twelveHourClockTime = "08:53"; + +// This is a wrong declaration syntax, variables can't start with numbers, special characters or contain reserved words. + +//I neglect that fact the two variables have the same names since Javascript variable names are not \ No newline at end of file diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index 117bcb2b6..125d5aa4f 100644 --- a/Sprint-1/exercises/count.js +++ b/Sprint-1/exercises/count.js @@ -4,3 +4,5 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing + +//Line 3 is about an assignment operator used to increase the count variable by 1. \ No newline at end of file diff --git a/Sprint-1/exercises/decimal.js b/Sprint-1/exercises/decimal.js index cc5947ce2..80b854c21 100644 --- a/Sprint-1/exercises/decimal.js +++ b/Sprint-1/exercises/decimal.js @@ -1,5 +1,9 @@ const num = 56.5678; +const wholeNumberPart = Math.floor(num); +const decimalPart = (num % 1).toFixed(4); +const roundedNum = Math.round(num); + // You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math // Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num ) diff --git a/Sprint-1/exercises/initials.js b/Sprint-1/exercises/initials.js index 6b80cd137..42e35acec 100644 --- a/Sprint-1/exercises/initials.js +++ b/Sprint-1/exercises/initials.js @@ -2,5 +2,7 @@ let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; +const initials = firstName[0] + middleName[0] + lastName[0] + // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index c91cd2ab3..324ef2f41 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -16,3 +16,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable + + +const dir = filePath.slice(0, lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".") + 1); diff --git a/Sprint-2/debug/0.js b/Sprint-2/debug/0.js index b46d471a8..24d2a0689 100644 --- a/Sprint-2/debug/0.js +++ b/Sprint-2/debug/0.js @@ -1,7 +1,10 @@ // Predict and explain first... function multiply(a, b) { - console.log(a * b); + return a * b; + // console.log(a * b); } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + +// The function returns undefined but it will log the product of the inputs to the console tab. \ No newline at end of file diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index df4020cae..31a6c7b60 100644 --- a/Sprint-2/debug/1.js +++ b/Sprint-2/debug/1.js @@ -1,8 +1,9 @@ // Predict and explain first... function sum(a, b) { - return; - a + b; + return a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +//The function returns undefined since the value has not been assigned to it. \ No newline at end of file diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index bae9652a8..a152e263c 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -3,7 +3,7 @@ const num = 103; function getLastDigit() { - return num.toString().slice(-1); + return num.toString().slice(num.length - 1); } console.log(`The last digit of 42 is ${getLastDigit(42)}`); @@ -12,3 +12,5 @@ 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 + +//Using slice(-1) is not a feasible method to use in this case. The correct way to do the code is by using num.toString().slice(num.length - 1) \ No newline at end of file diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index 74640e118..7af3d1d0e 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -7,3 +7,8 @@ function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } + + +capitalise('hello world') + +// This function is intended to get the first character in a string entered. \ No newline at end of file diff --git a/Sprint-2/errors/1.js b/Sprint-2/errors/1.js index 4602ed237..e3bb2884a 100644 --- a/Sprint-2/errors/1.js +++ b/Sprint-2/errors/1.js @@ -4,10 +4,13 @@ // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + // const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(convertToPercentage(0.5)); + + +// The function won't work because variable name declared cannot be used since it is used as a parameter. \ No newline at end of file diff --git a/Sprint-2/errors/2.js b/Sprint-2/errors/2.js index 814334d9e..d46622e06 100644 --- a/Sprint-2/errors/2.js +++ b/Sprint-2/errors/2.js @@ -3,8 +3,9 @@ // this function should square any number but instead we're going to get an error -function square(3) { +function square(num) { return num * num; } +// This function will return a syntax error because a number is used instead of a parameter. The correct function declaration should have a parameter instead of a value. \ No newline at end of file diff --git a/Sprint-2/extend/format-time.js b/Sprint-2/extend/format-time.js index f3b83062d..815e1cb65 100644 --- a/Sprint-2/extend/format-time.js +++ b/Sprint-2/extend/format-time.js @@ -22,3 +22,24 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("16:00"); +const targetOutput3 = "4:00 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +) + +const currentOutput4 = formatAs12HourClock("19:00"); +const targetOutput4 = "7:00 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +) + +const currentOutput5 = formatAs12HourClock("20:00"); +const targetOutput5 = "8:00 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +) \ No newline at end of file diff --git a/Sprint-2/implement/bmi.js b/Sprint-2/implement/bmi.js index 259f62d48..21c75d90d 100644 --- a/Sprint-2/implement/bmi.js +++ b/Sprint-2/implement/bmi.js @@ -13,3 +13,9 @@ // Given someone's weight in kg and height in metres // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place + +const findBMI = (weight, height) => { + return (weight / (height ** 2)).toFixed(1); +} + +findBMI(70, 1.73); \ No newline at end of file diff --git a/Sprint-2/implement/cases.js b/Sprint-2/implement/cases.js index 9e56a27b6..7a7d8556f 100644 --- a/Sprint-2/implement/cases.js +++ b/Sprint-2/implement/cases.js @@ -13,3 +13,13 @@ // You will need to come up with an appropriate name for the function // Use the string documentation to help you find a solution + +const upperSnakeCase = (input) => { + for ( let i = 0; i < input.length; i++) { + + } + const upperCase = input.replace(/\s+/g, '_').toUpperCase(); + console.log(upperCase) +} + +upperSnakeCase('lords of the rings'); \ No newline at end of file diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index 6265a1a70..ddce0849f 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -4,3 +4,21 @@ // 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 + +const 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"); + +console.log(`£${pounds}.${pence}`); +} + +toPounds('3455p'); \ No newline at end of file diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index 3fb167226..6872d3982 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,3 +8,9 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on + +const calcualteVat = (price) => { + return `£${price * 1.2}`; +} + +calcualteVat(60); \ No newline at end of file diff --git a/Sprint-2/interpret/time-format.js b/Sprint-2/interpret/time-format.js index c5a0c1619..5d12cdd33 100644 --- a/Sprint-2/interpret/time-format.js +++ b/Sprint-2/interpret/time-format.js @@ -19,13 +19,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? + // ~ pad function will also 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? + // ~ The value assigned to num will be the argument value 61 // c) What is the return value of pad is called for the first time? + // ~ The return value will be '01' // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer + // ~ The return value is 1 because the seconds input will subtract the remainingSeconds which is 1 and then divide the resultant value by 60, so the answer will give 1. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer + // ~ The return value is '01' because it will be calculating the remaining seconds which is 1 and as such the pad method will add 0 to it.