From 46cc0f6423efe869a871fe87ac200608d27219a3 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:17:13 +0000 Subject: [PATCH 01/18] solution to exercise --- Sprint-1/exercises/count.js | 2 ++ Sprint-1/exercises/decimal.js | 4 ++++ Sprint-1/exercises/initials.js | 5 +++++ Sprint-1/exercises/random.js | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index 117bcb2b6..58098bf5e 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 +// in line 3 the code is adding 1 to the variable count, that is after the line 3 is executed the value of count will now be 1. +// the = operator is used to assign a value to a variable. diff --git a/Sprint-1/exercises/decimal.js b/Sprint-1/exercises/decimal.js index cc5947ce2..8136794f9 100644 --- a/Sprint-1/exercises/decimal.js +++ b/Sprint-1/exercises/decimal.js @@ -7,3 +7,7 @@ const num = 56.5678; // Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) // Log your variables to the console to check your answers + +const wholeNumberPart = console.log(Math.floor(56.5678)); +const decimalPart = num - wholeNumberPart; +const roundedNum = console.log(Math.round(56.5678)); \ No newline at end of file diff --git a/Sprint-1/exercises/initials.js b/Sprint-1/exercises/initials.js index 6b80cd137..879de2322 100644 --- a/Sprint-1/exercises/initials.js +++ b/Sprint-1/exercises/initials.js @@ -4,3 +4,8 @@ let lastName = "Johnson"; // 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. + +// to select the first character of each variable i will use the charAt() also known as character at method which is used to extract a character at a specified index. +let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0); +// The console.log function in JavaScript is used to print (or log) messages to the console. +console.log(initials); diff --git a/Sprint-1/exercises/random.js b/Sprint-1/exercises/random.js index 292f83aab..11b0d2e88 100644 --- a/Sprint-1/exercises/random.js +++ b/Sprint-1/exercises/random.js @@ -7,3 +7,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + +// answer +//here the num is any integer between the value of 1 to 100, to breakdown the code +// the function Math.random() calls any number between 0 to 0.9999. lets say 0.5575 +// and this Math.random() * (maximum - minimum + 1) calculates the random number we got by (maximum - minimum + 1), which can be (100-1+1) which will give us the result of 100. +// (0.5575 *100) = 55.75 +// the function Math.floor will round the result of the previous step down to the nearest whole number, giving a random integer between 0 and 99 which in this will be 55. \ No newline at end of file From cefeea6f8fb412887bc72510327521f656213ec2 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:25:51 +0000 Subject: [PATCH 02/18] editing --- Sprint-1/exercises/random.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-1/exercises/random.js b/Sprint-1/exercises/random.js index 11b0d2e88..8c369f109 100644 --- a/Sprint-1/exercises/random.js +++ b/Sprint-1/exercises/random.js @@ -11,6 +11,17 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // answer //here the num is any integer between the value of 1 to 100, to breakdown the code // the function Math.random() calls any number between 0 to 0.9999. lets say 0.5575 + + // and this Math.random() * (maximum - minimum + 1) calculates the random number we got by (maximum - minimum + 1), which can be (100-1+1) which will give us the result of 100. + + // (0.5575 *100) = 55.75 -// the function Math.floor will round the result of the previous step down to the nearest whole number, giving a random integer between 0 and 99 which in this will be 55. \ No newline at end of file + + +// the function Math.floor will round the result of the previous step down to the nearest whole number, giving a random integer between 0 and 99 which in this will be 55. + + +// finally add the minimum to the result + +console.log(num); From 7b970c10df15579a14674e23fecc544d54e8665c Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:07:59 +0000 Subject: [PATCH 03/18] solving errors --- Sprint-1/errors/0.js | 5 +++-- Sprint-1/errors/1.js | 10 ++++++++-- Sprint-1/errors/2.js | 7 ++++++- Sprint-1/errors/3.js | 12 ++++++++++-- Sprint-1/errors/4.js | 14 ++++++++++++-- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Sprint-1/errors/0.js b/Sprint-1/errors/0.js index cf6c5039f..e828a21d0 100644 --- a/Sprint-1/errors/0.js +++ b/Sprint-1/errors/0.js @@ -1,2 +1,3 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +// This is just an instruction for the first activity - but it is just for human consumption +// We don't want the computer to run these 2 lines - how can we solve this problem? +// comments \ No newline at end of file diff --git a/Sprint-1/errors/1.js b/Sprint-1/errors/1.js index 7a43cbea7..bf4ef85cf 100644 --- a/Sprint-1/errors/1.js +++ b/Sprint-1/errors/1.js @@ -1,4 +1,10 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; -age = age + 1; +// const age = 33; +// age = age + 1; + + + // the problem is the variable age is declared as const which mean we can not change it to fix this we change it from const to let + + let age = 33; + age = age +1; diff --git a/Sprint-1/errors/2.js b/Sprint-1/errors/2.js index e09b89831..dc334bc74 100644 --- a/Sprint-1/errors/2.js +++ b/Sprint-1/errors/2.js @@ -1,5 +1,10 @@ // 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}`); +// console.log(`I was born in ${cityOfBirth}`); +// const cityOfBirth = "Bolton"; + +// the problem is we cannot access city of birth before initialization, here is the correct one + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index ec101884d..45e13f4ff 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -1,5 +1,5 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +// const cardNumber = 4533787178994213; +// const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +7,11 @@ 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 + + +// the code provided will produce an error cause the .slice() will only generate strings and arrays while the cardNumber is a number. +// to correct this i will introduce the .toString() to change it to a string, + +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); \ No newline at end of file diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 21dad8c5d..3f3f798ba 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,2 +1,12 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// const 12HourClockTime = "20:53"; +// const 24hourClockTime = "08:53"; + +// here the problem is a variable name in java script can not start with a number and also the reading in time 20:53 is in the 24 hr clock time + + +const twelveHourClockTime = "08:53"; +const twentyFourHourClockTime = "20:53"; + +console.log(twelveHourClockTime); +console.log(twentyFourHourClockTime); + From 2500cf3cddac2c14c1aead1e1e21b1bc5033a4cc Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:41:10 +0000 Subject: [PATCH 04/18] interpret exercise --- Sprint-1/interpret/percentage-change.js | 19 ++++++++++++++++++- Sprint-1/interpret/time-format.js | 14 ++++++++++++++ Sprint-1/interpret/to-pounds.js | 14 +++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Sprint-1/interpret/percentage-change.js b/Sprint-1/interpret/percentage-change.js index e24ecb8e1..1144df2a7 100644 --- a/Sprint-1/interpret/percentage-change.js +++ b/Sprint-1/interpret/percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -20,3 +20,20 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +//answers + +// a) +//on line 4, carPrice.replaceAll(",", ""), replaceAll is called on carPrice to remove the commas. +// on line 4, Number is called to replace the results of replaceAll to a number, cause they were strings. +// on line 5, priceAfterOneYear.replaceAll("," ""), replaceAll is called on priceAfterOneYear to remove thee comas. +// on line 5, Number is called to replace the results of replaceAll to a number, cause they were strings. +// on line 10, console.log(`The percentage change is ${percentageChange}`);, console.log is called to print the percentage. + +// b) the error is in line 5, priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); a comma is missing between the two strings, the correct one is priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + +// c) in line 4 and 5 the variables carPrice and priceAfterOneYear are replaced to a new values. first they are both strings with commas now they are numbers. + +// d) in javascript let and const are used to declare variables, so in the above code we have 4 declared variables: carPrice, priceAfterOneYear, priceDifference and percentageChange. + +// e) Number(carPrice.replaceAll(",","")): lets break it down. first the expression replaceAll(",","") is removing the comma (it was "10,000", now it is "10000"). and the second expression Number(carPrice.replaceAll(",","")) is changing the string to number(it was "10000" now it is 10000 ) \ No newline at end of file diff --git a/Sprint-1/interpret/time-format.js b/Sprint-1/interpret/time-format.js index 83232e43a..56e0fe972 100644 --- a/Sprint-1/interpret/time-format.js +++ b/Sprint-1/interpret/time-format.js @@ -22,3 +22,17 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +//answers + +// a) there are 6 variable declarations + +// b) there is one function, console.log(result); which prints the result. + +// c) the expression movieLength % 60, uses the % modular which returns the remaining of a division. here 8784 is the total movieLength in seconds and 60 is total seconds in one minute, so the total expression is saying how many seconds are remaining after we divide 8784 by 60 which will be 24 seconds. + +// d) line 4 calculating the the total number of whole minutes in the variable movieLength which is in seconds. + +// e) variable result represents time of the movieLength in hours:minutes:seconds. another name can be movieDuration. + +// f) i tried different values and the code works well. \ No newline at end of file diff --git a/Sprint-1/interpret/to-pounds.js b/Sprint-1/interpret/to-pounds.js index 60c9ace69..f99ec10a6 100644 --- a/Sprint-1/interpret/to-pounds.js +++ b/Sprint-1/interpret/to-pounds.js @@ -24,4 +24,16 @@ console.log(`£${pounds}.${pence}`); // 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" +// 1. const penceString = "399p": initializes a string variable with the value "399p" + +// to help me understand first i googled words that are new to me. penceString means the variable is a string, substring means a portion of a string, withOutTrailing mean describing a variable without a certain character, padded or pad means simply adding to a string. + +// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);, creates a new variable called penceStringWithoutTrailingP by removing the last character p, resulting in "399". + +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");, pads the string penceStringWithoutTrailingP with a leading "0" if it is less than 3 characters long, making it at least 3 characters. here "399" is three characters so it remains unchanged. + +// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);, will create a variable called const pounds y taking the characters from the start of paddedPenceNumberString up to but not including the last two characters which will result in "3". + +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");, will create a variable called const pence this line of code extracts the last two characters from a padded string representation of pence and ensures that it is represented as a two character string. + +// 6. console.log(`£${pounds}.${pence}`);, will print the amount of money in pounds and pence using template literals and then it outputs that formatted string to the console. \ No newline at end of file From 3ca4eca4108a73eb478251eef955d04b1aaf7529 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:23:33 +0000 Subject: [PATCH 05/18] debugging --- Sprint-2/debug/0.js | 11 ++++++++++- Sprint-2/debug/1.js | 16 +++++++++++++--- Sprint-2/debug/2.js | 25 +++++++++++++++++++------ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Sprint-2/debug/0.js b/Sprint-2/debug/0.js index b46d471a8..fcc4447e2 100644 --- a/Sprint-2/debug/0.js +++ b/Sprint-2/debug/0.js @@ -1,7 +1,16 @@ // Predict and explain first... +// function multiply(a, b) { +// console.log(a * b); +// } + +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + +// // correction +// the multiply code will not work cause the return is not defined. replace return (a*b) instead of console.log(a*b). function multiply(a, b) { - console.log(a * b); + return a * b; } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index df4020cae..253427f93 100644 --- a/Sprint-2/debug/1.js +++ b/Sprint-2/debug/1.js @@ -1,8 +1,18 @@ // Predict and explain first... +// function sum(a, b) { + +// return; +// a + b; +// } + +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +// correction +// the sum(10,32) in the console.log will give an undefined result. a + b should be on the same line of code with return. + function sum(a, b) { - return; - 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)}`); \ No newline at end of file diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index bae9652a8..0d7b6d359 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -1,14 +1,27 @@ // Predict and explain first... -const num = 103; +// const num = 103; -function getLastDigit() { +// 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)}`); + +// This program should tell the user the last digit of each number. +// Explain why getLastDigit is not working properly - correct the problem + +// correction +// when the num is defined in the above code it uses the const it should use the let, since getLastDigit is not a constant number. +// aan also getLastDigit in the function should have a parameter (num), else it will only give the last digit of the hardcoded num which is 103. + let num = 103; + +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 +console.log(`The last digit of 806 is ${getLastDigit(806)}`); \ No newline at end of file From 9fdeb38f36a1f7614efea40de6ef359921d930ef Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:06:15 +0000 Subject: [PATCH 06/18] correcting errors --- Sprint-2/errors/0.js | 12 +++++++++++- Sprint-2/errors/1.js | 17 +++++++++++++++-- Sprint-2/errors/2.js | 11 +++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index 74640e118..5cd61ea94 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -3,7 +3,17 @@ // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } + +//correction +// the problem is the capitalise function is that it is re declaring the str parameter inside the function using let. +// we canot do that cause the str is already a defined function. + function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +console.log(capitalise("emmanuel")) \ No newline at end of file diff --git a/Sprint-2/errors/1.js b/Sprint-2/errors/1.js index 4602ed237..1a28e38a6 100644 --- a/Sprint-2/errors/1.js +++ b/Sprint-2/errors/1.js @@ -3,11 +3,24 @@ // Why will an error occur when this program runs? // Try playing computer with the example to work out what is going on +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; + +// return percentage; +// } + +// console.log(decimalNumber); + +//correction +// the problem in the above code is that it redeclaring the decimalNumber with const. +// and the The variable decimalNumber is only available inside the function calling it outside will result in error + function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(convertToPercentage(0.5)); \ No newline at end of file diff --git a/Sprint-2/errors/2.js b/Sprint-2/errors/2.js index 814334d9e..c7b5e0fea 100644 --- a/Sprint-2/errors/2.js +++ b/Sprint-2/errors/2.js @@ -3,8 +3,15 @@ // this function should square any number but instead we're going to get an error -function square(3) { +// function square(3) { +// return num * num; +// } + +// correction +// the problem in the above code is it didnt defined the num as a parameter of square. + +function square(num) { return num * num; } - +console.log(square(3)) From cf6eacf3540b668bac7c9a6ccfa99d1ac2c52e88 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:37:42 +0000 Subject: [PATCH 07/18] implement solutions --- Sprint-2/extend/format-time.js | 2 ++ Sprint-2/implement/bmi.js | 21 +++++++++++++++++++++ Sprint-2/implement/cases.js | 19 +++++++++++++++++++ Sprint-2/implement/to-pounds.js | 25 +++++++++++++++++++++++++ Sprint-2/implement/vat.js | 13 +++++++++++++ 5 files changed, 80 insertions(+) diff --git a/Sprint-2/extend/format-time.js b/Sprint-2/extend/format-time.js index f3b83062d..3e19c2da6 100644 --- a/Sprint-2/extend/format-time.js +++ b/Sprint-2/extend/format-time.js @@ -22,3 +22,5 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +// input 1, \ No newline at end of file diff --git a/Sprint-2/implement/bmi.js b/Sprint-2/implement/bmi.js index 259f62d48..8c7470d21 100644 --- a/Sprint-2/implement/bmi.js +++ b/Sprint-2/implement/bmi.js @@ -13,3 +13,24 @@ // 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 + + +// solution + +function calculateBMI(weight, height) { + + const heightSquared = height * height; + + + const bmi = weight / heightSquared; + + + return parseFloat(bmi.toFixed(1)); + } + + + const weight = 70; + const height = 1.73; + const bmi = calculateBMI(weight, height); + console.log(`Your BMI is: ${bmi}`); + \ No newline at end of file diff --git a/Sprint-2/implement/cases.js b/Sprint-2/implement/cases.js index 9e56a27b6..61dba0ea0 100644 --- a/Sprint-2/implement/cases.js +++ b/Sprint-2/implement/cases.js @@ -13,3 +13,22 @@ // You will need to come up with an appropriate name for the function // Use the string documentation to help you find a solution + + +//solution + +function toUpperSnakeCase(input) { + + const withUnderscores = input.replace(/ /g, "_"); + + + const upperSnakeCase = withUnderscores.toUpperCase(); + + + return upperSnakeCase; + } + + + console.log(toUpperSnakeCase("hello there")); + console.log(toUpperSnakeCase("lord 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..b9e466a60 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -4,3 +4,28 @@ // 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 + + +// solution + +function toPounds(amountInPence) { + + const penceStringWithoutTrailingP = amountInPence.substring( 0,amountInPence.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("399p")); + console.log(toPounds("25p")); + \ No newline at end of file diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index 3fb167226..80554325e 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,3 +8,16 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on + + +// solution + +function calculatePriceWithVAT(price) { + + const vatInclusivePrice = price * 1.2; + + return parseFloat(vatInclusivePrice.toFixed(2)); + } + + console.log(calculatePriceWithVAT(23)); + \ No newline at end of file From e1421fd474658cd9060dfc87ffb86c3fc9f64c0d Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:48:32 +0000 Subject: [PATCH 08/18] interpret solutions --- Project-CLI-Treasure-Hunt | 1 + Sprint-2/interpret/time-format.js | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 160000 Project-CLI-Treasure-Hunt diff --git a/Project-CLI-Treasure-Hunt b/Project-CLI-Treasure-Hunt new file mode 160000 index 000000000..5ca380b14 --- /dev/null +++ b/Project-CLI-Treasure-Hunt @@ -0,0 +1 @@ +Subproject commit 5ca380b141dfe60780a233a7d7c7a08485af2df9 diff --git a/Sprint-2/interpret/time-format.js b/Sprint-2/interpret/time-format.js index c5a0c1619..7a7c6ee06 100644 --- a/Sprint-2/interpret/time-format.js +++ b/Sprint-2/interpret/time-format.js @@ -29,3 +29,11 @@ function formatTimeDisplay(seconds) { // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer + +// answers + +// a) three times, for total hours, remaining minuts and remaining seconds +// b) num = totalHours = 0 +// c) ("00") +// d) num = remainingSeconds = 1 +// e) pad(1) to "01", it converts 1 to a string character "01" \ No newline at end of file From 412c625aef8cd182dbcbfe8bca914c0ff9769ec3 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:51:58 +0000 Subject: [PATCH 09/18] editting --- Sprint-2/interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/interpret/time-format.js b/Sprint-2/interpret/time-format.js index 7a7c6ee06..faea28dac 100644 --- a/Sprint-2/interpret/time-format.js +++ b/Sprint-2/interpret/time-format.js @@ -36,4 +36,4 @@ function formatTimeDisplay(seconds) { // b) num = totalHours = 0 // c) ("00") // d) num = remainingSeconds = 1 -// e) pad(1) to "01", it converts 1 to a string character "01" \ No newline at end of file +// e) pad(1) to "01", it converts 1 to a string character "01" . \ No newline at end of file From cbc5c15351fd202060e5a08412188e9ffe7947f7 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:14:07 +0000 Subject: [PATCH 10/18] implementing the getAngleType --- Sprint-3/implement/get-angle-type.js | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Sprint-3/implement/get-angle-type.js b/Sprint-3/implement/get-angle-type.js index db952494f..bb1f4bc7b 100644 --- a/Sprint-3/implement/get-angle-type.js +++ b/Sprint-3/implement/get-angle-type.js @@ -25,3 +25,47 @@ // Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" + +// solution + +function getAngleType(angle) { + //to get the right amgle + if (angle === 90) { + return "Right angle"; + //to get the acute angle + } else if (angle < 90) { + return "Acute angle"; + // to get the obtuse angle + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + // to get the stright line, or angle + } else if (angle === 180) { + return "Straight angle"; + // to get the reflex angle + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + // else return invalid imput or angle + } else { + return "Invalid angle"; + } +} + +// Example Usage: +console.log(getAngleType(45)); // Output: "Acute angle" +console.log(getAngleType(90)); // Output: "Right angle" +console.log(getAngleType(135)); // Output: "Obtuse angle" +console.log(getAngleType(180)); // Output: "Straight angle" +console.log(getAngleType(270)); // Output: "Reflex angle" +console.log(getAngleType(360)); // Output: "Invalid angle" + + + +function getAngleType(angle){ + const rightAngles = (angle = 90) + const acuteAngles = (angle < 90) + const obtuseAngles = (90 < angle > 180) + const straightAngles = (angle = 180) + const reflexAngles = (180 < angle > 360) + return (getAngleType) +} + From 89df8195d214c7d52c05c4b3afc5b598f951fd78 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:52:21 +0000 Subject: [PATCH 11/18] implementing is proper function --- Sprint-3/implement/is-proper-fraction.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-3/implement/is-proper-fraction.js b/Sprint-3/implement/is-proper-fraction.js index 6493da0be..7788212f8 100644 --- a/Sprint-3/implement/is-proper-fraction.js +++ b/Sprint-3/implement/is-proper-fraction.js @@ -32,3 +32,14 @@ // target output: false // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. // These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator. + +function isProperFraction(Numerator, Denominator ){ + if (Math.abs(Numerator) < Math.abs(Denominator)) { + return true; + } else if (Denominator === 0){ + return "Error"; + }else { + return false; + } + +} \ No newline at end of file From 93706140ad5ed88bb46c7bb92da880f46b2535ba Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:44:36 +0000 Subject: [PATCH 12/18] implementing get card value --- Sprint-3/implement/get-card-value.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-3/implement/get-card-value.js b/Sprint-3/implement/get-card-value.js index edaeb8275..d3df813d8 100644 --- a/Sprint-3/implement/get-card-value.js +++ b/Sprint-3/implement/get-card-value.js @@ -29,3 +29,20 @@ // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." + + +// solution + +function getCardValue(card) { + if (typeof card === "number" && card >= 2 && card <= 9) { + return card; + } else if (["10", "J", "Q", "K"].includes(card)) { + return 10; + } else if (card === "A") { + return 11; + } else { + throw new Error("Invalid card"); + } +} + + From 29d4ef0d2f1bb4ab416222fb918ae96a131883c1 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:46:47 +0000 Subject: [PATCH 13/18] changes --- Sprint-3/implement/get-angle-type.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Sprint-3/implement/get-angle-type.js b/Sprint-3/implement/get-angle-type.js index bb1f4bc7b..c24d5bf7d 100644 --- a/Sprint-3/implement/get-angle-type.js +++ b/Sprint-3/implement/get-angle-type.js @@ -50,22 +50,9 @@ function getAngleType(angle) { } } -// Example Usage: -console.log(getAngleType(45)); // Output: "Acute angle" -console.log(getAngleType(90)); // Output: "Right angle" -console.log(getAngleType(135)); // Output: "Obtuse angle" -console.log(getAngleType(180)); // Output: "Straight angle" -console.log(getAngleType(270)); // Output: "Reflex angle" -console.log(getAngleType(360)); // Output: "Invalid angle" - - - -function getAngleType(angle){ - const rightAngles = (angle = 90) - const acuteAngles = (angle < 90) - const obtuseAngles = (90 < angle > 180) - const straightAngles = (angle = 180) - const reflexAngles = (180 < angle > 360) - return (getAngleType) -} + + + + + From 921b6ce87a86ff07b5d10640a273788da7ff4192 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:21:39 +0000 Subject: [PATCH 14/18] implementing valid traiangle --- Sprint-3/implement/is-valid-triangle.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sprint-3/implement/is-valid-triangle.js b/Sprint-3/implement/is-valid-triangle.js index f3643ab22..ee3d4b6ff 100644 --- a/Sprint-3/implement/is-valid-triangle.js +++ b/Sprint-3/implement/is-valid-triangle.js @@ -1,4 +1,4 @@ -// Implement a function isValidTriangle + // Implement a function isValidTriangle // Terms // the Triangle Inequality says: the sum of any two sides is always greater than the third side. // practical examples: @@ -21,7 +21,7 @@ // When the sum of any two side lengths is less than or equal to the length of the third side (i.e., a + b <= c, a + c <= b, b + c <= a), // Then it should return false because these conditions violate the Triangle Inequality, which states that the sum of the lengths of any two sides of a triangle must be greater than the length of the third side. -// scenario: invalid triangle +// scenario: invalid triangle; // Check for Valid Input: // Given the sides a, b, and c, // When any of the sides are less than or equal to zero, @@ -33,3 +33,19 @@ // Then it should return true because the input forms a valid triangle. // This specification outlines the behavior of the isValidTriangle function for different input scenarios, ensuring it properly checks for invalid side lengths and whether they form a valid triangle according to the Triangle Inequality Theorem. + + +//solution + +function isValidTriangle(a, b, c) { + if (a <= 0 || b <= 0 || c <= 0) { + return "Invalid triangle"; + } + if (a + b <= c || a + c <= b || b + c <= a) { + return "Invalid triangle"; + } + + return "Valid triangle"; +} + + From 6f7180be33f505e0af743b78a3b02c2b3783c189 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:05:08 +0000 Subject: [PATCH 15/18] testing angle type --- Sprint-3/implement/get-angle-type.js | 4 +-- Sprint-3/implement/getAngleType.test.js | 47 +++++++++++++++++++++++++ Sprint-3/implement/package.json | 10 ++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 Sprint-3/implement/getAngleType.test.js create mode 100644 Sprint-3/implement/package.json diff --git a/Sprint-3/implement/get-angle-type.js b/Sprint-3/implement/get-angle-type.js index c24d5bf7d..fd732fd16 100644 --- a/Sprint-3/implement/get-angle-type.js +++ b/Sprint-3/implement/get-angle-type.js @@ -36,7 +36,7 @@ function getAngleType(angle) { } else if (angle < 90) { return "Acute angle"; // to get the obtuse angle - } else if (angle > 90 && angle < 180) { + } else if (90 < angle < 180) { return "Obtuse angle"; // to get the stright line, or angle } else if (angle === 180) { @@ -50,7 +50,7 @@ function getAngleType(angle) { } } - +module.exports = getAngleType; diff --git a/Sprint-3/implement/getAngleType.test.js b/Sprint-3/implement/getAngleType.test.js new file mode 100644 index 000000000..465d47d38 --- /dev/null +++ b/Sprint-3/implement/getAngleType.test.js @@ -0,0 +1,47 @@ +test('should return "Right angle" exactly for 90 degrees', function() { + const currentInput = getAngleType (90); + const targetInput = "Right angle"; + expect(currentInput).toBe(targetInput); +}); + +test('should return "Acute angle" when degrees is less than 90 degrees', function() { + const currentInput = getAngleType (45); + const targetInput = "Acute angle"; + expect(currentInput).toBe(targetInput); +}); + +test('should return "Obtuse angle" when degrees are between 90 and 180 degrees', function() { + const currentInput = getAngleType(135); + const targetInput = "Obtuse angle"; + expect(currentInput).toBe(targetInput); +}); + +test('should return "Straight angle" exactly for 180 degrees', function() { + const currentInput = getAngleType(180); + const targetInput = "Straight angle"; + expect(currentInput).toBe(targetInput); +}); + +test('should return "Reflex angle" when degrees are between 180 and 360 degrees', function() { + const currentInput = getAngleType(270); + const targetInput = "Reflex angle"; + expect(currentInput).toBe(targetInput); +}); + +test('should return "Invalid angle" for angles less than 0 degrees', function() { + const currentInput = getAngleType(-45); + const targetInput = "Invalid angle"; + expect(currentInput).toBe(targetInput); +}); + +test('should return "Invalid angle" for angles equal to or greater than 360 degrees', function() { + const currentInput = getAngleType(360); + const targetInput = "Invalid angle"; + expect(currentInput).toBe(targetInput); +}); + +test('should return "Invalid angle" for non-numeric inputs', function() { + const currentInput = getAngleType("hello"); + const targetInput = "Invalid angle"; + expect(currentInput).toBe(targetInput); +}); \ No newline at end of file diff --git a/Sprint-3/implement/package.json b/Sprint-3/implement/package.json new file mode 100644 index 000000000..f9546ce93 --- /dev/null +++ b/Sprint-3/implement/package.json @@ -0,0 +1,10 @@ +{ + "name": "week-4-test-example", + "description": "An example application showing how to write tests using the jest framework", + "scripts": { + "test": "jest" + }, + "devDependencies": { + "jest": "^29.5.0" + } + } \ No newline at end of file From 0dd59e4acec1955887be5be40bb741aec23a4220 Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:09:03 +0000 Subject: [PATCH 16/18] testing get card values --- Sprint-3/implement/get-card-value.js | 1 + Sprint-3/implement/getCardValue.test.js | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 Sprint-3/implement/getCardValue.test.js diff --git a/Sprint-3/implement/get-card-value.js b/Sprint-3/implement/get-card-value.js index d3df813d8..5770600ff 100644 --- a/Sprint-3/implement/get-card-value.js +++ b/Sprint-3/implement/get-card-value.js @@ -46,3 +46,4 @@ function getCardValue(card) { } +module.exports = getCardValue; \ No newline at end of file diff --git a/Sprint-3/implement/getCardValue.test.js b/Sprint-3/implement/getCardValue.test.js new file mode 100644 index 000000000..fe4447874 --- /dev/null +++ b/Sprint-3/implement/getCardValue.test.js @@ -0,0 +1,33 @@ +test('should return the numeric value for cards 2 to 9', function() { + for (let card = 2; card <= 9; card++) { + expect(getCardValue(card)).toBe(card); + } +}); + +test('should return 10 for face cards "10", "J", "Q", "K"', function() { + expect(getCardValue("10")).toBe(10); + expect(getCardValue("J")).toBe(10); + expect(getCardValue("Q")).toBe(10); + expect(getCardValue("K")).toBe(10); +}); + +test('should return 11 for the Ace card "A"', function() { + expect(getCardValue("A")).toBe(11); +}); + +test('should throw an error for invalid card types (e.g., "Z")', function() { + expect(() => getCardValue("Z")).toThrow("Invalid card"); +}); + +test('should throw an error for invalid numeric cards (e.g., 1, 0, -3)', function() { + expect(() => getCardValue(1)).toThrow("Invalid card"); + expect(() => getCardValue(0)).toThrow("Invalid card"); + expect(() => getCardValue(-3)).toThrow("Invalid card"); +}); + +test('should throw an error for non-numeric and non-string inputs', function() { + expect(() => getCardValue(null)).toThrow("Invalid card"); + expect(() => getCardValue(undefined)).toThrow("Invalid card"); + expect(() => getCardValue([])).toThrow("Invalid card"); + expect(() => getCardValue({})).toThrow("Invalid card"); +}); \ No newline at end of file From b3a66a42035fba695b4755a381ef145a411fcb9e Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:12:40 +0000 Subject: [PATCH 17/18] testing propper fructions --- Sprint-3/implement/getProperFraction.test.js | 42 ++++++++++++++++++++ Sprint-3/implement/is-proper-fraction.js | 4 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Sprint-3/implement/getProperFraction.test.js diff --git a/Sprint-3/implement/getProperFraction.test.js b/Sprint-3/implement/getProperFraction.test.js new file mode 100644 index 000000000..74bd0184a --- /dev/null +++ b/Sprint-3/implement/getProperFraction.test.js @@ -0,0 +1,42 @@ +test('should return true when absolute value of numerator is less than absolute value of denominator', function() { + expect(isProperFraction(1, 2)).toBe(true); + expect(isProperFraction(-3, 5)).toBe(true); + expect(isProperFraction(3, -7)).toBe(true); + expect(isProperFraction(-4, -9)).toBe(true); +}); + +test('should return false when absolute value of numerator is greater than or equal to absolute value of denominator', function() { + expect(isProperFraction(5, 3)).toBe(false); + expect(isProperFraction(-8, 4)).toBe(false); + expect(isProperFraction(6, -6)).toBe(false); + expect(isProperFraction(-10, -10)).toBe(false); +}); + +test('should return "Error" when denominator is 0', function() { + expect(isProperFraction(1, 0)).toBe("Error"); + expect(isProperFraction(-5, 0)).toBe("Error"); +}); + +test('should handle edge cases with zero numerator', function() { + expect(isProperFraction(0, 5)).toBe(true); + expect(isProperFraction(0, -5)).toBe(true); + expect(isProperFraction(0, 0)).toBe("Error"); +}); + +test('should handle non-integer numerators and denominators', function() { + expect(isProperFraction(1.5, 2.5)).toBe(true); + expect(isProperFraction(3.5, 2.5)).toBe(false); + expect(isProperFraction(-2.1, -2.2)).toBe(true); +}); + +test('should handle large values for numerator and denominator', function() { + expect(isProperFraction(1000000, 1000001)).toBe(true); + expect(isProperFraction(1000000, 1000000)).toBe(false); + expect(isProperFraction(-100000000, -99999999)).toBe(false); +}); + +test('should handle invalid inputs gracefully', function() { + expect(() => isProperFraction(null, 5)).toThrow(); + expect(() => isProperFraction(3, undefined)).toThrow(); + expect(() => isProperFraction([], {})).toThrow(); +}); \ No newline at end of file diff --git a/Sprint-3/implement/is-proper-fraction.js b/Sprint-3/implement/is-proper-fraction.js index 7788212f8..24d8e066e 100644 --- a/Sprint-3/implement/is-proper-fraction.js +++ b/Sprint-3/implement/is-proper-fraction.js @@ -42,4 +42,6 @@ function isProperFraction(Numerator, Denominator ){ return false; } -} \ No newline at end of file +} + +module.exports = isProperFraction; \ No newline at end of file From 9d93d0a17b5663f7f3d8260151ede22cd6774dad Mon Sep 17 00:00:00 2001 From: Emmanuelgessessew <163059051+Emmanuelgessessew@users.noreply.github.com> Date: Mon, 20 Jan 2025 01:03:45 +0000 Subject: [PATCH 18/18] changes --- Sprint-3/implement/get-angle-type.js | 19 +++++++------------ Sprint-3/implement/getAngleType.test.js | 1 + Sprint-3/implement/getCardValue.test.js | 1 + Sprint-3/implement/getProperFraction.test.js | 2 +- Sprint-3/implement/is-proper-fraction.js | 8 +++++--- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Sprint-3/implement/get-angle-type.js b/Sprint-3/implement/get-angle-type.js index fd732fd16..113dc86d6 100644 --- a/Sprint-3/implement/get-angle-type.js +++ b/Sprint-3/implement/get-angle-type.js @@ -29,30 +29,25 @@ // solution function getAngleType(angle) { - //to get the right amgle + // To get the right angle if (angle === 90) { return "Right angle"; - //to get the acute angle + // To get the acute angle } else if (angle < 90) { return "Acute angle"; - // to get the obtuse angle - } else if (90 < angle < 180) { + // To get the obtuse angle + } else if (angle > 90 && angle < 180) { return "Obtuse angle"; - // to get the stright line, or angle + // To get the straight line, or angle } else if (angle === 180) { return "Straight angle"; - // to get the reflex angle + // To get the reflex angle } else if (angle > 180 && angle < 360) { return "Reflex angle"; - // else return invalid imput or angle + // Else return invalid input or angle } else { return "Invalid angle"; } } module.exports = getAngleType; - - - - - diff --git a/Sprint-3/implement/getAngleType.test.js b/Sprint-3/implement/getAngleType.test.js index 465d47d38..7cc233053 100644 --- a/Sprint-3/implement/getAngleType.test.js +++ b/Sprint-3/implement/getAngleType.test.js @@ -1,3 +1,4 @@ +const getAngleType = require('./getAngleType'); test('should return "Right angle" exactly for 90 degrees', function() { const currentInput = getAngleType (90); const targetInput = "Right angle"; diff --git a/Sprint-3/implement/getCardValue.test.js b/Sprint-3/implement/getCardValue.test.js index fe4447874..165e1b3f7 100644 --- a/Sprint-3/implement/getCardValue.test.js +++ b/Sprint-3/implement/getCardValue.test.js @@ -1,3 +1,4 @@ +const getCardValue = require('./getCardValue'); test('should return the numeric value for cards 2 to 9', function() { for (let card = 2; card <= 9; card++) { expect(getCardValue(card)).toBe(card); diff --git a/Sprint-3/implement/getProperFraction.test.js b/Sprint-3/implement/getProperFraction.test.js index 74bd0184a..03f113b73 100644 --- a/Sprint-3/implement/getProperFraction.test.js +++ b/Sprint-3/implement/getProperFraction.test.js @@ -39,4 +39,4 @@ test('should handle invalid inputs gracefully', function() { expect(() => isProperFraction(null, 5)).toThrow(); expect(() => isProperFraction(3, undefined)).toThrow(); expect(() => isProperFraction([], {})).toThrow(); -}); \ No newline at end of file +}); diff --git a/Sprint-3/implement/is-proper-fraction.js b/Sprint-3/implement/is-proper-fraction.js index 24d8e066e..e6ccc2681 100644 --- a/Sprint-3/implement/is-proper-fraction.js +++ b/Sprint-3/implement/is-proper-fraction.js @@ -34,14 +34,16 @@ // These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator. function isProperFraction(Numerator, Denominator ){ + if (Denominator === 0) { + throw new Error("Denominator cannot be zero"); + } if (Math.abs(Numerator) < Math.abs(Denominator)) { return true; - } else if (Denominator === 0){ - return "Error"; }else { return false; } } -module.exports = isProperFraction; \ No newline at end of file +module.exports = isProperFraction; +