diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..70254cdf0 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// The code will throw an error because the variable `str` is being declared twice in the same scope. + // 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; } +capitalise("hello,this is a test"); + +// // =============> write your explanation here // =============> write your new code here +//// The error occurs because the variable `str`is declared twice in the same scope,which is not allowed in JavaScript. \ 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..58d69cff0 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,6 +2,8 @@ // Why will an error occur when this program runs? // =============> write your prediction here +//Decimal number is undefined +//we ll got syntax error as we are declaring a new variable // Try playing computer with the example to work out what is going on @@ -18,3 +20,11 @@ console.log(decimalNumber); // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + + const percentage = `${decimalNumber * 100}%`; + + return percentage; + } + + result = console.log(convertToPercentage(0.5)); \ 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..adc36768b 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,16 +5,28 @@ // =============> write your prediction of the error here +//we will get an error bcs the parameter of the function need to string type not number so it can be something like num + function square(3) { return num * num; } // =============> write the error message here +//Output: + +/index.js:1 +function square(3) { + ^ +SyntaxError: Unexpected number // =============> explain this error message here // Finally, correct the code to fix the problem // =============> write your new code here - +//THe error message tells that we wrote a syntax that JavaScript does not understand. +function square(num) { + return num * num; +} +result = console.log(square(3)); \ 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..fba46cb3d 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,9 +1,15 @@ // Predict and explain first... // =============> write your prediction here - +// What I predict is that the console.log which is outside the function will pass the parameters 10 and 32 to the function +// Then the console.log(a * b) which is inside the function will print out + // to the terminal the multiplication of a by b function multiply(a, b) { - console.log(a * b); + const multiplicationResult = (a * b); + return multiplicationResult; + + + } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..4ebc9ae87 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,16 @@ // Predict and explain first... // =============> write your prediction here - +// The code will not return the sum of the two numbers because the return statement is placed before the actual addition operation. function sum(a, b) { - return; - a + b; + return a + b; + + } 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..2c5b07cd7 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,7 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here - +// The code will not retuen the last digit of the number because the function getLastDigit is not correctly defined to aacept the parameter. const num = 103; function getLastDigit() { @@ -16,9 +16,19 @@ 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 +// Because every time we are passing the parameters we are actually using the num value and return it. // =============> write your explanation here // 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 +const 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)}`); \ 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..bdbac2e48 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // 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 + squareHeight =height * height; + bmi = weight / squareHeight; + return bmi.0toFixed(1); + } \ 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..aa8720ef7 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,7 @@ // 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 +function upperSnakeCase(str) { + return (upperSnakeCase = str.replaceAll(" ", "_").toUpperCase()); +} +console.log(upperSnakeCase("Congratulations having a boy! 🎉")); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..d7b4978d9 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,9 @@ // 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 + +function toPounds(kg) { + const pounds =kg *2.20462; + return pounds.toFixed(2); + +} \ No newline at end of file diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..096efa57a 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,4 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); +// \ No newline at end of file