From ac4dc6c655583f6f14d91632c92f314a91291645 Mon Sep 17 00:00:00 2001 From: vboxuser Date: Sat, 11 Nov 2023 15:12:50 +0000 Subject: [PATCH 1/2] errors, exercises and explore done --- week-1/errors/1.js | 3 ++- week-1/errors/3.js | 5 ++++- week-1/errors/4.js | 5 +++-- week-1/exercises/count.js | 2 ++ week-1/exercises/decimal.js | 10 +++++++--- week-1/exercises/initials.js | 2 ++ week-1/exercises/paths.js | 4 ++++ week-1/exercises/random.js | 4 ++++ week-1/explore/chrome.md | 3 +++ 9 files changed, 31 insertions(+), 7 deletions(-) diff --git a/week-1/errors/1.js b/week-1/errors/1.js index 7a43cbea..2dc1d4d6 100644 --- a/week-1/errors/1.js +++ b/week-1/errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +var age = 33; age = age + 1; +console.log(age); \ No newline at end of file diff --git a/week-1/errors/3.js b/week-1/errors/3.js index ffa72ca4..5516239b 100644 --- a/week-1/errors/3.js +++ b/week-1/errors/3.js @@ -1,7 +1,10 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +let stringNumber = cardNumber.toString(); +const last4Digits =stringNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working // Make and explain a prediction about why the code won't work + // // Then try updating the expression last4Digits is assigned to, in order to get the correct value +console.log(last4Digits); \ No newline at end of file diff --git a/week-1/errors/4.js b/week-1/errors/4.js index 21dad8c5..d6d3ccb1 100644 --- a/week-1/errors/4.js +++ b/week-1/errors/4.js @@ -1,2 +1,3 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime12 = "20:53"; +const hourClockTime24 = "08:53"; + //variable can not start with numer symbol \ No newline at end of file diff --git a/week-1/exercises/count.js b/week-1/exercises/count.js index 117bcb2b..b9ff8770 100644 --- a/week-1/exercises/count.js +++ b/week-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 variable count is increase by one. + console.log(count) diff --git a/week-1/exercises/decimal.js b/week-1/exercises/decimal.js index bd4a4740..e3b54f4f 100644 --- a/week-1/exercises/decimal.js +++ b/week-1/exercises/decimal.js @@ -1,10 +1,14 @@ const num = 56.5467; -// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math - +// You should look up Math functions for this exercise // Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num ) + var wholeNumberpart= Math.floor(num); // Create a variable called decimalPart and assign to it an expression that evaluates to 0.5467 ( the decimal part of num ) + var decimalpart= num-Math.floor(num); // Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) - + var rounded= Math.round(num); // Log your variables to the console to check your answers +console.log(wholeNumberpart); +console.log(decimalpart); + console.log(rounded); \ No newline at end of file diff --git a/week-1/exercises/initials.js b/week-1/exercises/initials.js index 50b62103..84b05da0 100644 --- a/week-1/exercises/initials.js +++ b/week-1/exercises/initials.js @@ -4,3 +4,5 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string in upper case to form the user's initials // Log the variable in each case +var initials= `${firstName.charAt(0).toUpperCase()} ${middleName.charAt(0).toUpperCase()}${lastName.charAt(0).toUpperCase()}`; +console.log(initials) \ No newline at end of file diff --git a/week-1/exercises/paths.js b/week-1/exercises/paths.js index c91cd2ab..4af6dc9b 100644 --- a/week-1/exercises/paths.js +++ b/week-1/exercises/paths.js @@ -15,4 +15,8 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable +const dirpath= filePath.slice(0,-8); +console.log(dirpath); +console.log(base); // Create a variable to store the ext part of the variable + diff --git a/week-1/exercises/random.js b/week-1/exercises/random.js index 79a4a4d5..11762e26 100644 --- a/week-1/exercises/random.js +++ b/week-1/exercises/random.js @@ -4,6 +4,10 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // In this exercise, you will need to work out what num represents? + // Try breaking down the expression and using documentation to explain what it means + // the num variable first find random number 1 up to 100 then round the number + // and multiplay by maximum -minimum and add one finally add minimum // It will help to think about the order in which expressions are evaluated // Try logging the value of num several times to build an idea of what the program is doing + console.log(num); \ No newline at end of file diff --git a/week-1/explore/chrome.md b/week-1/explore/chrome.md index e7dd5fea..5fec4553 100644 --- a/week-1/explore/chrome.md +++ b/week-1/explore/chrome.md @@ -11,8 +11,11 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +alert is small box at the top that display a text Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? +prompt is a dialog box that the propmts user for input What is the return value of `prompt`? +ok or cancel From 6e6ede5679bd280e16a5afb6a03a6607705f2a04 Mon Sep 17 00:00:00 2001 From: nohetekelmariyam Date: Sat, 2 Dec 2023 14:18:21 +0000 Subject: [PATCH 2/2] i fix all --- week-1/exercises/initials.js | 6 ++++-- week-1/interpret/percentage-change.js | 8 +++++--- week-1/interpret/time-format.js | 12 ++++++----- week-1/interpret/to-pounds.js | 9 ++++++--- week-2/errors/0.js | 4 +++- week-2/errors/2.js | 10 ++++----- week-2/implement/bmi.js | 12 +++++++++++ week-2/implement/cases.js | 8 ++++++++ week-2/implement/to-pounds.js | 18 +++++++++++++++++ week-2/implement/vat.js | 13 +++++++++++- week-2/interpret/time-format.js | 14 ++++++++----- week-3/implement/get-angle-type.js | 15 ++++++++++++++ week-3/implement/get-card-value.js | 2 +- week-3/implement/is-proper-fraction.js | 14 ++++++++++++- week-3/implement/is-valid-triangle.js | 27 ++++++++++++++++++++----- week-4/implement/creditCardValidator.js | 14 +++++++++++++ 16 files changed, 153 insertions(+), 33 deletions(-) create mode 100644 week-4/implement/creditCardValidator.js diff --git a/week-1/exercises/initials.js b/week-1/exercises/initials.js index 84b05da0..8a76504c 100644 --- a/week-1/exercises/initials.js +++ b/week-1/exercises/initials.js @@ -4,5 +4,7 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string in upper case to form the user's initials // Log the variable in each case -var initials= `${firstName.charAt(0).toUpperCase()} ${middleName.charAt(0).toUpperCase()}${lastName.charAt(0).toUpperCase()}`; -console.log(initials) \ No newline at end of file +var initials = `${firstName.charAt(0).toUpperCase()} ${middleName + .charAt(0) + .toUpperCase()}${lastName.charAt(0).toUpperCase()}`; +console.log(initials); diff --git a/week-1/interpret/percentage-change.js b/week-1/interpret/percentage-change.js index 49b0ac15..515b497f 100644 --- a/week-1/interpret/percentage-change.js +++ b/week-1/interpret/percentage-change.js @@ -12,9 +12,11 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made - +//2 Number and replaceAll // b) Identify all the lines that are variable reassignment statements - +//line 4,5 // c) Identify all the lines that are variable declarations - +//line 1,2,7,8 // d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//Number(carPrice.replaceAll(",","")) is doing first variable carPrice .. +//..is a string, so function Number change this string in to num and function replaceAll change all , in to .. diff --git a/week-1/interpret/time-format.js b/week-1/interpret/time-format.js index 7961fe0d..66e69cef 100644 --- a/week-1/interpret/time-format.js +++ b/week-1/interpret/time-format.js @@ -14,15 +14,17 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? - +//there are 7 variable in this pice of code // b) How many function calls are there? - +// we don't have function here // c) Using documentation on MDN, explain what the expression movieLength % 60 represents - +//remainingSeconds = movieLength % 60;=> this expression is .. +//..help us to get the remaining second after variable movieLength divide by 60 // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - +// totalMinutes assign to change moveLength in to minutes by subtract from movieLength // e) What do you think the variable result represents? Can you think of a better name for this variable? - +//result represent the remainingHours, remainingMinutes and the remainingSeconds +//i suggest replacing the variable name "result" with "remainingHours" to enhance clarity. // f) Think about whether this program will work for all values of movieLength. // Think of what values may cause problems for the code. // Decide the result should be for those values, then test it out. diff --git a/week-1/interpret/to-pounds.js b/week-1/interpret/to-pounds.js index 196be3b2..5116e529 100644 --- a/week-1/interpret/to-pounds.js +++ b/week-1/interpret/to-pounds.js @@ -1,16 +1,19 @@ const penceString = "399p"; - +// "penceSting" variable declare with "399p" value const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); - +// "penceStringWithoutTrailingP" is create new value by taking substring from "penceString" +// function subString remove the last index by subtract -1 from "penceString"length const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//paddedPenceNumberString is create a value by add 0 in "penceStringWithoutTrailingP" const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); - +//"pounds" is create a value by taking subString from "paddedPenceNumberString" +//function subString remove the last index by subtract -2 from "paddedPenceNumberString"length const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); diff --git a/week-2/errors/0.js b/week-2/errors/0.js index 58b1349d..3f6194d2 100644 --- a/week-2/errors/0.js +++ b/week-2/errors/0.js @@ -4,6 +4,8 @@ // interpret the error message and figure out why it's happening, if your prediction was wrong function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + var str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +var str = "uygugbu"; +console.log(capitalise(str)); diff --git a/week-2/errors/2.js b/week-2/errors/2.js index b0454133..d7826706 100644 --- a/week-2/errors/2.js +++ b/week-2/errors/2.js @@ -1,10 +1,8 @@ - // Predict and explain first... // this function should square any number but instead we're going to get an error // what is happening? How can we fix it? - -function square(3) { - return num * num; +// to obtain the first square number we need multiply a number by it self +function square(num) { + return num * num; } - - +console.log(square(2)); diff --git a/week-2/implement/bmi.js b/week-2/implement/bmi.js index 172c7c9a..19b46dfb 100644 --- a/week-2/implement/bmi.js +++ b/week-2/implement/bmi.js @@ -13,3 +13,15 @@ // Given someone's weight in kg and height in metres // When we call this function with the weight and height // Then it returns their Body Mass Index to 1 decimal place +function bmiCalculation(weight, height) { + if (typeof weight === "number" && typeof height === "number") { + const bmi = weight / (height * height); + + return `${bmi.toFixed(1)}`; + } else { + return " please use the right unit"; + } +} +var weight = 60; +var height = 1.64; +console.log(bmiCalculation(weight, height)); diff --git a/week-2/implement/cases.js b/week-2/implement/cases.js index 56b0d8d0..8b9faf13 100644 --- a/week-2/implement/cases.js +++ b/week-2/implement/cases.js @@ -15,3 +15,11 @@ // Come up with a clear, simple name for the function // Use the string documentation to help you plan your solution +let string = ""; +function upperSnakeCase(string) { + const wordSplit = string.split(" "); + const wordToCapital = wordSplit.map((word) => word.toUpperCase()); + const wordJoin = wordToCapital.join("_"); + return wordJoin; +} +console.log(upperSnakeCase("nohe tekel mariyam")); diff --git a/week-2/implement/to-pounds.js b/week-2/implement/to-pounds.js index 7add3d05..1fbaf2c8 100644 --- a/week-2/implement/to-pounds.js +++ b/week-2/implement/to-pounds.js @@ -3,3 +3,21 @@ // Take this code and turn it into a reusable block of code. // Declare a function called toPounds with an appropriately named parameter. // 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}`; +} +var penceString = "299p"; +console.log(toPounds(penceString)); diff --git a/week-2/implement/vat.js b/week-2/implement/vat.js index 44c38d74..227b5881 100644 --- a/week-2/implement/vat.js +++ b/week-2/implement/vat.js @@ -1,10 +1,21 @@ // When selling goods, most are subject to the 20% standard rate of VAT. // You must add 20% to the price you charge for the goods. // You can do this by multiplying the price you charge by 1.2. -// For example, if your business sells sports equipment for £50, you multiply £50 by 1.2 for a total VAT inclusive price of £60. +// For example, if your business sells sports equipment for £50, you multiply £50 by 1.2 for .. +//..a total VAT inclusive price of £60. // Implement a function that calculates the new price with VAT (Value Added Tax) added on. // Given a number, // When I call this function with a number // Then it returns the new price with VAT added on +function productCostWithVat(price) { + if (typeof price === "number") { + const vatPrice = price * 1.2; + return `£${vatPrice.toFixed(2)}`; + } else { + return "don't waste my time"; + } +} +var price = 399; +console.log(productCostWithVat(price)); diff --git a/week-2/interpret/time-format.js b/week-2/interpret/time-format.js index 15793e20..6ad58740 100644 --- a/week-2/interpret/time-format.js +++ b/week-2/interpret/time-format.js @@ -26,18 +26,22 @@ console.log(formatTimeDisplay(143)); // Questions // a) When formatTimeDisplay is called how many times will pad be called? - +//3 time // Call formatTimeDisplay with an input of 143, now answer the following: // b) What value is assigned to the parameter num when pad is called for the first time? - + //remainingHours or 00 // c) What is the return value of pad when it is called for the first time? - + //00 // d) What is the value assigned to the parameter num when pad // is called for the last time in this program? Explain your answer - + //if second is less than 10 it would add 0 but now it is more than 10 so it return 23. // e) What is the return value when pad is called // for the last time in this program? Explain your answer - + // pad return 23 b/c 23 is greater than 10 // f) Research an alternative way of padding the numbers in this code. // Look up the string functions on mdn + / //funtion pad(num) + //{ + // return num.toString().padstart(2,"0"); + //} \ No newline at end of file diff --git a/week-3/implement/get-angle-type.js b/week-3/implement/get-angle-type.js index 9dd3a210..d8c6cd35 100644 --- a/week-3/implement/get-angle-type.js +++ b/week-3/implement/get-angle-type.js @@ -21,3 +21,18 @@ // Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" +function getAngleType(Angles) { + if (Angles == 90) { + return "Right angle"; + } else if (Angles < 90) { + return "Acute angle"; + } else if (Angles == 180) { + return "Straight angle"; + } else if (Angles > 180 && AngleS < 360) { + return "reflex angle"; + } else { + return "it's not angle"; + } +} +var AngleS = 350; +console.log(getAngleType(AngleS)); diff --git a/week-3/implement/get-card-value.js b/week-3/implement/get-card-value.js index 0dd74fbc..16b3f6fd 100644 --- a/week-3/implement/get-card-value.js +++ b/week-3/implement/get-card-value.js @@ -9,7 +9,7 @@ // Given a card string in the format "A♠" (representing a card in blackjack), // When the function getCardValue is called with this card string as input, // Then it should return the numerical card value - +function getCardValue() {} // Handle Number Cards (2-10): // Given a card with a rank between "2" and "10", // When the function is called with such a card, diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 31da32b5..26dfde62 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -11,7 +11,19 @@ // Input: numerator = 2, denominator = 3 // target output: true // Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true. - +function isProperFraction(numerator, denominator) { + if (numerator >= denominator && denominator != 0) { + return "false"; + } else if (numerator < denominator) { + return "True"; + } else { + return "error"; + } +} +console.log(isProperFraction(5, 2)); +console.log(isProperFraction(3, 0)); +console.log(isProperFraction(-4, 7)); +console.log(isProperFraction(3, 3)); // Improper Fraction check: // Input: numerator = 5, denominator = 2 // target output: false diff --git a/week-3/implement/is-valid-triangle.js b/week-3/implement/is-valid-triangle.js index 7b22836b..ac46ba06 100644 --- a/week-3/implement/is-valid-triangle.js +++ b/week-3/implement/is-valid-triangle.js @@ -12,19 +12,36 @@ // It's also true that b + c > a // It's also true that a + c > b -// In our function isValidTriangle, we need to return false for any triangle where the sum of any two sides is less than or equal to the length of the third side. -// and we need to return true for any triangle where the sum of any two sides is greater than the length of the third side. +// In our function isValidTriangle, we need to return false for any triangle where the sum of any two +//..sides is less than or equal to the length of the third side. +// and we need to return true for any triangle where the sum of any two sides is greater than the length +//..of the third side. // Acceptance criteria: // Given the lengths of three sides of a triangle (a, b, c), // When the function isValidTriangle is called with these side lengths as input, // Then it should: - +function isValidTriangle(side1, side2, side3) { + if ( + side1 + side2 <= side3 || + side1 + side3 <= side2 || + (side2 + side3 <= side1 && side1 <= 0) || + side2 <= 0 || + side3 <= 0 + ) { + return "false"; + } else { + return "turn"; + } +} // scenario: invalid triangle // Given the side lengths a, b, and c, -// 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. +// 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 // Check for Valid Input: diff --git a/week-4/implement/creditCardValidator.js b/week-4/implement/creditCardValidator.js new file mode 100644 index 00000000..d094c01d --- /dev/null +++ b/week-4/implement/creditCardValidator.js @@ -0,0 +1,14 @@ +//n this project you'll write a script that validates whether or not a credit card number is valid. + +//Here are the rules for a valid number: + +//- Number must be 16 digits, all of them must be numbers. +//- You must have at least two different digits represented (all of the digits cannot be the same). +//- The final digit must be even. +//- The sum of all the digits must be greater than 16. +function creditCardValidator(cardNumber) { + if (typeof cardNumber !== "number" && cardNumber.length !== 16); + { + return "not card"; + } +}