diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..8a9217077 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -4,10 +4,23 @@ // 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; -} +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } // =============> write your explanation here + +// Error at line 8 +//SyntaxError: Identifier 'str' has already been declared +// the function has alreayd a parameter called "str"and +// we are trying decare a new variable with the same name + // =============> write your new code here + +function capitalise(str) { + let newCap = `${str[0].toUpperCase()}${str.slice(1)}`; + return newCap; +} +console.log(capitalise("hello")); +console.log(capitalise("apple")); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..4bf2c1dda 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -5,16 +5,34 @@ // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); // =============> write your explanation here +// declaration variable name has been declared the same in the function declaration +//(decimalNumber) and inside the function in a new variable line 9 = const decimalNumber + +//SyntaxError: Identifier 'decimalNumber' has already been declared + + + // Finally, correct the code to fix the problem // =============> write your new code here +//using the function with any code: + +function convertToPercentage(decimalNumber) { + + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage( 0.5)); +console.log(convertToPercentage(2)); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..73e018f47 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,16 +5,25 @@ // =============> write your prediction of the error here -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here +//SyntaxError: Unexpected number + // =============> explain this error message here +// passing nunber 3 in the function without declarint it as a number to be square // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + const squareNumber= (num * num); + return squareNumber ; +} +console.log (square(3)); +console.log (square(4)); \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..0a939507e 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -8,7 +8,21 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +//output= The result of multiplying 10 and 32 is undefined + // =============> write your explanation here +//The function runs console.log(10 * 32) print the result = 320 +// after it runs the function dosen't have a return anything ang gives = undefined. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> to use the function that gives a result need to use RETURN not consol.log inside the function + +function multiply(num1, num2) { + // const forAllMutiply = (a * b); + // return forAllMutiply; //return can be use for diferents values/results + return num1 * num2; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + +//output= The result of multiplying 10 and 32 is 320 \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..685c4d3f2 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,25 @@ // Predict and explain first... -// =============> write your prediction here +// =============> looking at it I think the sytntaks is worng return; a+b; + +// function sum(a, b) { +// return; +// a + b; +// } + +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +// =============> +// I declare in the scope of function what a,b need to do return +// call the function with the template literal +// wich will give me the Text sentence with the result of any sum + +// Finally, correct the code to fix the problem +// =============> function sum(a, b) { - return; - a + b; + const newSum = a + b; + return newSum; + } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..e4da0583d 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,42 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> it is declaring num fisrt wich wil work but the function will stop after the +//calculate 103 results. after run Return if the results. -const num = 103; +// I din't predict rigt it gives the results all using the const Num= 103 -function getLastDigit() { - return num.toString().slice(-1); -} +// the consolo.log wont work -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)}`); +// const num = 103; + +// 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)}`); // Now run the code and compare the output to your prediction // =============> write the output here // Explain why the output is the way it is -// =============> write your explanation here +// =============> it is using the const 103 for all the results + // Finally, correct the code to fix the problem -// =============> write your new code here -// This program should tell the user the last digit of each number. -// Explain why getLastDigit is not working properly - correct the problem + + +function getLastDigit(numtoCalculate) { //give a input to the function to use + const num = numtoCalculate.toString().slice(-1); //declare a const adding values to what to do + return num; // return the process +} + +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)}`); + +//output +// The last digit of 42 is 2 +// The last digit of 105 is 5 +// The last digit of 806 is 6 \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..b21c35845 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,14 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + let heightSquare = height * height; + let wheightCal = weight / heightSquare; + let result1 = wheightCal.toFixed(1); + //toFixed() returns a string, not a number. + // need to convert the result to a number + let tranftoNumber= parseFloat(result1); + return tranftoNumber; +} + +console.log (calculateBMI (56, 1.65)) +// return the BMI of someone based off their weight and height \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..a94849dc7 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,24 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + + +//1- methodo that take space add _ ? +//2- methodo find first index of ech word +//3- methodo to tranform string to upercase = toUpperCase() +//4- return the value + + + +function takeSapcestoUpercase(inputString) { + + let takespace = inputString.split(" "); + let transfStringAgain = takespace.join("_"); + let changeUper = transfStringAgain.toUpperCase(); + return changeUper; +}; + let textExemple = "cat dog rabbit"; +console.log(takeSapcestoUpercase(textExemple)); + + let textExemple2 = "hello there"; + console.log(takeSapcestoUpercase(textExemple2)); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..153237020 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -1,6 +1,43 @@ // In Sprint-1, there is a program written in interpret/to-pounds.js // You will need to take this code and turn it into a reusable block of code. + +// need to get car price = let fullPrice +//need get priceOneyear= let priceOneyear +// need take the spaces off the both variables +//need check the diference of the prices +//multiplay the result for 100 to check the percentage +// return the result with template literals + +//function needs to be valid with diferents inputs + // 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 + + +// let carPrice = "10,000"; +// let priceAfterOneYear = "8,543"; + +// carPrice = Number(carPrice.replaceAll(",", ""));// 10000 +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); //8543 + +// const priceDifference = carPrice - priceAfterOneYear; //1457 +// const percentageChange = (priceDifference / carPrice) * 100; //145700 + +// console.log(`The percentage change is ${percentageChange}`); //14.57 + +function toPounds(fullPrice, priceOneyear) { + + fullPrice = Number(fullPrice.replaceAll(",", "")); + priceOneyear = Number(priceOneyear.replaceAll(",", "")); + + const priceDifference = fullPrice - priceOneyear; + + const percentageChange = (priceDifference / fullPrice) * 100; + +// console.log(`The percentage change is ${percentageChange}`); + return percentageChange; +} + +console.log (toPounds( "100,000", "98,000")); diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..4c56d8d84 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -2,14 +2,15 @@ function pad(num) { return num.toString().padStart(2, "0"); } -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; +function formatTimeDisplay(seconds) { // seconds = 61 + const remainingSeconds = seconds % 60; // 1 + const totalMinutes = (seconds - remainingSeconds) / 60; // 61 - 1) / 60 = 1 + const remainingMinutes = totalMinutes % 60; // 1 / 60 = 1 + const totalHours = (totalMinutes - remainingMinutes) / 60; // 0 return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)); // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions @@ -17,18 +18,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here + //3 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? -// =============> write your answer here +// 0 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// 00 // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// 1 // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// 01 diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..105aa844d 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,38 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("19:00"); +const targetOutput3 = "7:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput5 = formatAs12HourClock("19:00"); +const targetOutput5 = "7:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput4 = formatAs12HourClock("22:00"); +const targetOutput4 = "10:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput6 = formatAs12HourClock("22:00. "); +const targetOutput6= "10:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput6 = formatAs12HourClock("22:00. "); +const targetOutput6 = "10:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); \ No newline at end of file