From dcc0a14730f2d08a960206103237ca6ef5013998 Mon Sep 17 00:00:00 2001 From: abdullah1 Date: Sat, 18 Nov 2023 13:55:36 +0000 Subject: [PATCH 1/7] javascripe update --- week-1/errors/0.js | 5 +++-- week-1/errors/1.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/week-1/errors/0.js b/week-1/errors/0.js index cf6c5039..88800a6f 100644 --- a/week-1/errors/0.js +++ b/week-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. +// to solve this problem to make this line as commit // diff --git a/week-1/errors/1.js b/week-1/errors/1.js index 7a43cbea..3d30fc6a 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; +let age = 33; age = age + 1; +console.log(age); + From f8bb6db04232574000d63f25a241b6ca2f4f1d6f Mon Sep 17 00:00:00 2001 From: abdullah1 Date: Sat, 18 Nov 2023 13:55:51 +0000 Subject: [PATCH 2/7] errors update --- week-1/errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/errors/2.js b/week-1/errors/2.js index e09b8983..b446a423 100644 --- a/week-1/errors/2.js +++ b/week-1/errors/2.js @@ -2,4 +2,4 @@ // what's the error ? console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; +const cityOfBirth = "Bolton"; \ No newline at end of file From 70a7f3466d5d004628731a7b07e78671ba9add6a Mon Sep 17 00:00:00 2001 From: abdullah1 Date: Sat, 18 Nov 2023 16:54:45 +0000 Subject: [PATCH 3/7] done exercises --- week-1/errors/2.js | 5 +++-- week-1/errors/3.js | 3 ++- week-1/errors/4.js | 4 ++-- week-1/exercises/count.js | 2 +- week-1/exercises/decimal.js | 11 ++++++++++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/week-1/errors/2.js b/week-1/errors/2.js index b446a423..dc39dd18 100644 --- a/week-1/errors/2.js +++ b/week-1/errors/2.js @@ -1,5 +1,6 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? - +const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; \ No newline at end of file + +//console.log ('I was born in ${city0fBirth}');// diff --git a/week-1/errors/3.js b/week-1/errors/3.js index ffa72ca4..b5a9de37 100644 --- a/week-1/errors/3.js +++ b/week-1/errors/3.js @@ -1,5 +1,6 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = String (cardNumber).slice(-4); +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working diff --git a/week-1/errors/4.js b/week-1/errors/4.js index 21dad8c5..b2d629c2 100644 --- a/week-1/errors/4.js +++ b/week-1/errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime24 = "20:53"; +const hourClockTime12 = "08:53"; diff --git a/week-1/exercises/count.js b/week-1/exercises/count.js index 117bcb2b..5b54df1a 100644 --- a/week-1/exercises/count.js +++ b/week-1/exercises/count.js @@ -1,6 +1,6 @@ let count = 0; count = count + 1; - +//line 3 describe // 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 diff --git a/week-1/exercises/decimal.js b/week-1/exercises/decimal.js index bd4a4740..0deb50fc 100644 --- a/week-1/exercises/decimal.js +++ b/week-1/exercises/decimal.js @@ -1,10 +1,19 @@ 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 https://developer.mozilla.o/rg/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 ) // Create a variable called decimalPart and assign to it an expression that evaluates to 0.5467 ( the decimal part of num ) // 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 =Math.floor(num) + +console.log(wholeNumberPart); +const decimalPart=num-wholeNumberPart +console.log(decimalPart); +const roundedNum=Math.round(num) +console.log(roundedNum); + From 328e5cf23d9a9c21674a78e7380fa4e0ae25691e Mon Sep 17 00:00:00 2001 From: abdullah1 Date: Tue, 28 Nov 2023 21:37:48 +0000 Subject: [PATCH 4/7] update js1 --- week-1/exercises/initials.js | 13 ++++++++++--- week-1/exercises/paths.js | 6 +++++- week-1/exercises/random.js | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/week-1/exercises/initials.js b/week-1/exercises/initials.js index 50b62103..400ff2bc 100644 --- a/week-1/exercises/initials.js +++ b/week-1/exercises/initials.js @@ -1,6 +1,13 @@ -let firstName = "Creola"; -let middleName = "Katherine"; -let lastName = "Johnson"; +let firstName = "creola"; +let middleName = "katherine"; +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 +let firstInitial = firstName.charAt(0).toUpperCase(); +console.log(firstInitial); +let middleInitial = middleName.charAt(0).toUpperCase(); +console.log(middleInitial); +let lastInitial = lastName.charAt(0).toUpperCase(); +console.log(lastInitial); +console.log(`${firstInitial}.${middleInitial}.${lastInitial} `); diff --git a/week-1/exercises/paths.js b/week-1/exercises/paths.js index c91cd2ab..90bf39da 100644 --- a/week-1/exercises/paths.js +++ b/week-1/exercises/paths.js @@ -13,6 +13,10 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); - +console.log(lastSlashIndex); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable +let = filePath ("/") +console.log (dirPart,filePath); + +console.log(filePath+ lastSlashIndex) diff --git a/week-1/exercises/random.js b/week-1/exercises/random.js index 79a4a4d5..7985208a 100644 --- a/week-1/exercises/random.js +++ b/week-1/exercises/random.js @@ -7,3 +7,6 @@ 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 several times to build an idea of what the program is doing + const minImum = Math.floor(sum) + let.Math.floor(Math.random() * 6 + 1); + console.log(minImum); \ No newline at end of file From a54967b1b73cdf70a7b22dea8924b515a785ad79 Mon Sep 17 00:00:00 2001 From: abdullah1 Date: Tue, 28 Nov 2023 22:44:03 +0000 Subject: [PATCH 5/7] updateweek2 --- week-2/errors/0.js | 3 ++- week-2/errors/1.js | 3 +++ week-2/errors/2.js | 3 +++ week-2/implement/bmi.js | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/week-2/errors/0.js b/week-2/errors/0.js index 58b1349d..0bfedcc6 100644 --- a/week-2/errors/0.js +++ b/week-2/errors/0.js @@ -4,6 +4,7 @@ // 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)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } + // variable name without let \ No newline at end of file diff --git a/week-2/errors/1.js b/week-2/errors/1.js index 14b5b511..2ff1de9a 100644 --- a/week-2/errors/1.js +++ b/week-2/errors/1.js @@ -11,3 +11,6 @@ function convertToPercentage(decimalNumber) { } console.log(decimalNumber); + // you can't declare constant with the same name as a parameter within the same scope + // decimalNumber is not defined. + // value numbers should not take string \ No newline at end of file diff --git a/week-2/errors/2.js b/week-2/errors/2.js index b0454133..036e38d4 100644 --- a/week-2/errors/2.js +++ b/week-2/errors/2.js @@ -5,6 +5,9 @@ function square(3) { return num * num; + console.log (square(3));//12 + console.log (square(6));//18 } + diff --git a/week-2/implement/bmi.js b/week-2/implement/bmi.js index 172c7c9a..c6013a67 100644 --- a/week-2/implement/bmi.js +++ b/week-2/implement/bmi.js @@ -13,3 +13,4 @@ // 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 + From 1541dd856e47e234da90bb6472a6cd3866e7ce57 Mon Sep 17 00:00:00 2001 From: abdullah1 Date: Fri, 1 Dec 2023 16:44:14 +0000 Subject: [PATCH 6/7] exmple change --- week-2/errors/0.js | 5 ++++- week-2/errors/2.js | 11 ++++++----- week-2/implement/bmi.js | 6 ++++++ week-2/implement/cases.js | 7 +++++++ week-2/implement/to-pounds.js | 4 ++++ week-2/implement/vat.js | 5 +++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/week-2/errors/0.js b/week-2/errors/0.js index 0bfedcc6..615e1a57 100644 --- a/week-2/errors/0.js +++ b/week-2/errors/0.js @@ -4,7 +4,10 @@ // interpret the error message and figure out why it's happening, if your prediction was wrong function capitalise(str) { - str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; + } +console.log(capitalise("bule")); // variable name without let \ No newline at end of file diff --git a/week-2/errors/2.js b/week-2/errors/2.js index 036e38d4..f128250a 100644 --- a/week-2/errors/2.js +++ b/week-2/errors/2.js @@ -3,11 +3,12 @@ // 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; - console.log (square(3));//12 - console.log (square(6));//18 -} + function square { + return num * num; + + } + var result = square(3); + console.log("square" (3)); diff --git a/week-2/implement/bmi.js b/week-2/implement/bmi.js index c6013a67..a0cf7610 100644 --- a/week-2/implement/bmi.js +++ b/week-2/implement/bmi.js @@ -14,3 +14,9 @@ // When we call this function with the weight and height // Then it returns their Body Mass Index to 1 decimal place +function bmi (w,h){ + h = h*h; + let x = h/w; + return (x); +} +console.log(Bmi("60")); \ No newline at end of file diff --git a/week-2/implement/cases.js b/week-2/implement/cases.js index 56b0d8d0..6699ad07 100644 --- a/week-2/implement/cases.js +++ b/week-2/implement/cases.js @@ -15,3 +15,10 @@ // Come up with a clear, simple name for the function // Use the string documentation to help you plan your solution + + + + + + + \ No newline at end of file diff --git a/week-2/implement/to-pounds.js b/week-2/implement/to-pounds.js index 7add3d05..dd6363e4 100644 --- a/week-2/implement/to-pounds.js +++ b/week-2/implement/to-pounds.js @@ -3,3 +3,7 @@ // 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(meat){ + const meatstring +} +console.log(num); \ No newline at end of file diff --git a/week-2/implement/vat.js b/week-2/implement/vat.js index 44c38d74..e8eaa211 100644 --- a/week-2/implement/vat.js +++ b/week-2/implement/vat.js @@ -8,3 +8,8 @@ // Given a number, // When I call this function with a number // Then it returns the new price with VAT added on + function addVat(price){ + price*1.2 + result(price); + } + console.log(addVat(150)); \ No newline at end of file From f275546610b39efe1cf439350cea7bee186d8926 Mon Sep 17 00:00:00 2001 From: abdullah1 Date: Fri, 8 Dec 2023 19:14:31 +0000 Subject: [PATCH 7/7] update2 --- week-1/exercises/paths.js | 2 +- week-1/interpret/percentage-change.js | 6 ++++-- week-1/interpret/time-format.js | 2 +- week-2/errors/2.js | 6 +++--- week-2/implement/bmi.js | 11 ++++++----- week-2/implement/cases.js | 8 ++++++++ week-2/implement/to-pounds.js | 8 +++++--- week-3/implement/get-angle-type.js | 18 ++++++++++++++++++ week-3/implement/get-card-value.js | 16 ++++++++++++++++ week-3/implement/is-proper-fraction.js | 26 ++++++++++++++++++++++++++ week-3/implement/is-valid-triangle.js | 12 ++++++++++++ week-3/refactor/format-as-12-hours.js | 16 ++++++++++++++++ week-3/refactor/is-vowel.js | 2 +- 13 files changed, 117 insertions(+), 16 deletions(-) diff --git a/week-1/exercises/paths.js b/week-1/exercises/paths.js index 90bf39da..1f669d21 100644 --- a/week-1/exercises/paths.js +++ b/week-1/exercises/paths.js @@ -18,5 +18,5 @@ console.log(lastSlashIndex); // Create a variable to store the ext part of the variable let = filePath ("/") console.log (dirPart,filePath); - +const console.log(filePath+ lastSlashIndex) diff --git a/week-1/interpret/percentage-change.js b/week-1/interpret/percentage-change.js index 49b0ac15..8ad02f70 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 - +There are four function +line 1 line 2 , line line 7 and line 8 // b) Identify all the lines that are variable reassignment statements - +line 1 is carpeice line 2 is priceAfterOneYear , line 7 priceDifference line 8 priceDifference // c) Identify all the lines that are variable declarations +var to 10000 , var is "8553" , var 7 is carPrice -priceAfterOneYear and var 8 priceDifference / carPrice // d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? diff --git a/week-1/interpret/time-format.js b/week-1/interpret/time-format.js index 7961fe0d..d62c479a 100644 --- a/week-1/interpret/time-format.js +++ b/week-1/interpret/time-format.js @@ -14,7 +14,7 @@ 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 seven variable declared // b) How many function calls are there? // c) Using documentation on MDN, explain what the expression movieLength % 60 represents diff --git a/week-2/errors/2.js b/week-2/errors/2.js index f128250a..9a499fa3 100644 --- a/week-2/errors/2.js +++ b/week-2/errors/2.js @@ -3,12 +3,12 @@ // 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 { + function square (num) { return num * num; } - var result = square(3); - console.log("square" (3)); + + console.log("square" (8)); diff --git a/week-2/implement/bmi.js b/week-2/implement/bmi.js index a0cf7610..fdc3e096 100644 --- a/week-2/implement/bmi.js +++ b/week-2/implement/bmi.js @@ -14,9 +14,10 @@ // When we call this function with the weight and height // Then it returns their Body Mass Index to 1 decimal place -function bmi (w,h){ - h = h*h; - let x = h/w; - return (x); +function bim (weigh,height){ + height = height*weigh; + let bim = ("weigh*height"); + } -console.log(Bmi("60")); \ No newline at end of file + +console.log(bim); \ No newline at end of file diff --git a/week-2/implement/cases.js b/week-2/implement/cases.js index 6699ad07..50265262 100644 --- a/week-2/implement/cases.js +++ b/week-2/implement/cases.js @@ -9,6 +9,14 @@ // When we call this function with the input string // Then it returns the string in UPPER_CAMEL_CASE, so "HELLO_THERE" + +function cases (str){ + str =`${str.Uppercase()}` + str =`${str.Snake_cases()}` + return +} +console.log("cases"); + // Test case: we expect "lord of the rings" to be "LORD_OF_THE_RINGS" // Test case: we expect "the great gatsby" to be "THE_GREAT_GATSBY" // Test case: we expect "the da vinci code" to be "THE_DA_VINCI_CODE" diff --git a/week-2/implement/to-pounds.js b/week-2/implement/to-pounds.js index dd6363e4..0f8d9fc4 100644 --- a/week-2/implement/to-pounds.js +++ b/week-2/implement/to-pounds.js @@ -3,7 +3,9 @@ // 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(meat){ - const meatstring +function toPounds(jainnah){ + return `${Number( jainnah / 1200).toFixed(2)} pounds`; + + } -console.log(num); \ No newline at end of file +console.log(toPounds(20)); \ 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..b363c587 100644 --- a/week-3/implement/get-angle-type.js +++ b/week-3/implement/get-angle-type.js @@ -21,3 +21,21 @@ // 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(angle){ + if (angle==90){ + return "right angle"; + } else if(angle < 90){ + return "acute angle"; + } else if (angle == 180){ + return "straight angle"; + } else if (angle >90 && angle <180){ + return "obtuse angle"; + } else if (angle >180 && angle <360){ + return "reflex angle"; + } else { + return "invalid"; + } +} +console.log(getAngleType(90)); \ No newline at end of file diff --git a/week-3/implement/get-card-value.js b/week-3/implement/get-card-value.js index 0dd74fbc..b9356822 100644 --- a/week-3/implement/get-card-value.js +++ b/week-3/implement/get-card-value.js @@ -29,3 +29,19 @@ // 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." + function getCardValue(card){ + const rank = card.slice(0,-1) + if (rank >=2 && rank<= 10){ + return parseInt(rank); + } + if (["j" ,"Q","R"].includes(rank)){ + return 10; + } + if (rank =="A"){ + return 11; + } + else { + return "invalid card rank" + } + } + console.log("getCardValue()"); \ No newline at end of file diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 31da32b5..75556d39 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -33,3 +33,29 @@ // 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. + +// Define the function +function isProperFraction(numerator, denominator) { + var x = numerator; + var y = denominator; + + var outputVal = x % y; + if (outputVal > 0) { + return false; + } else { + return true; + } +} + +// Call the function with some example values +var numeratorExample = 14; +var denominatorExample = 2; + +var result = isProperFraction(numeratorExample, denominatorExample); + +// Log the result to the console +if (result === true) { + console.log("target output: true"); +} else { + console.log("target output: false"); +} diff --git a/week-3/implement/is-valid-triangle.js b/week-3/implement/is-valid-triangle.js index 7b22836b..6c29fad9 100644 --- a/week-3/implement/is-valid-triangle.js +++ b/week-3/implement/is-valid-triangle.js @@ -38,3 +38,15 @@ // 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. + +function isValidTriangle(a, b, c) { + if (a <= 0 || b <= 0 || c <= 0) { + return "false"; + } ; + if (a - b <= c || a + c <= b || b + c <= a) { + return "false"; + else { + return true; + } +} +console.log(isValidTriangle(3, 7, 2)); diff --git a/week-3/refactor/format-as-12-hours.js b/week-3/refactor/format-as-12-hours.js index 41603122..8ee47c63 100644 --- a/week-3/refactor/format-as-12-hours.js +++ b/week-3/refactor/format-as-12-hours.js @@ -4,3 +4,19 @@ // Store this expression in a variable and reference it twice in the function in the correct place // Explain why it makes more sense to store this expression in a variable + +function formatAs12Hours(time) { + const hours24 = Number(time.slice(0, 2)); + + if (hours24 < 0 || hours24 > 23) { + return "Invalid hours in time string"; // check vaild in 24hours fromat + } else if (hours24 === 0) { + return "midnight"; + } else { + const hours12 = hours24 % 12; + const period = hours24 < 12 ? "AM" : "PM"; + return `${hours12 === 0 ? 12 : hours12}:${time.slice(3)} ${period}`; + } +} + +console.log(formatAs12Hours("08:30")); // Example usage diff --git a/week-3/refactor/is-vowel.js b/week-3/refactor/is-vowel.js index db675d2b..f88c0aa5 100644 --- a/week-3/refactor/is-vowel.js +++ b/week-3/refactor/is-vowel.js @@ -2,7 +2,7 @@ function isVowel(letter) { return ( letter === "a" || letter === "e" || - letter === "i" || + // letter === "i" || letter === "i" || letter === "o" || letter === "u"