diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..9527e1f388 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,6 +1,8 @@ // Predict and explain first... // =============> write your prediction here +//str has allready been declared. + // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -10,4 +12,14 @@ function capitalise(str) { } // =============> write your explanation here +/* + I think its because of been called multiple times, at "let str" after "funtion capitalise(str)" + changing "let str" to "let capitalised" should help the issue. +*/ // =============> write your new code here +/* +function capitalise(str) { + let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalised; +} +*/ diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..4b1edbfd5f 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,7 +2,11 @@ // Why will an error occur when this program runs? // =============> write your prediction here - +/* +Yes an error will occur. +decimalNumber has been declared +an error will another errour would be for, decimalNumber is not defined +*/ // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { @@ -15,6 +19,19 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============> write your explanation here - +/* +decimalNumber has been called and set as a const. +"console.log(decimalNumber)" wont work as decimalNumber only excistes inside the function not outside it. +*/ // Finally, correct the code to fix the problem // =============> write your new code here +/* +function convertToPercentage(decimalNumber) { + const decimal = 0.5; + const percentage = `${decimal * 100}%`; + + return percentage; + +} + console.log(convertToPercentage) +*/ diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..54c10f809f 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,6 +1,5 @@ // Predict and explain first BEFORE you run any code... - // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here @@ -10,11 +9,17 @@ function square(3) { } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here - +// the (3) is a value not a variable or parimitor name, it should be num instead for the functino to work corretly. // Finally, correct the code to fix the problem // =============> write your new code here - - +/* + function square(num) { + return num * num; + } + + 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 b27511b417..61b63482f2 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// is going to have undefined function multiply(a, b) { console.log(a * b); @@ -9,6 +10,17 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here - +/* +its going to have undefined for the ${multiply(10, 32) as in teh function it has console.log. +It needs to have "return" in order for it to keep teh vaule for the function as it is only displying it right now. +*? // Finally, correct the code to fix the problem // =============> write your new code here +/* +function multiply(a, b) { + return(a * b); +} + +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 37cedfbcfd..8a20ff68ce 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +// return undefined for ${sum(10, 32)} function sum(a, b) { return; @@ -9,5 +10,13 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// in the function return is split from a + b by ; // Finally, correct the code to fix the problem // =============> write your new code here +/* +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +*/ \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..0a1472fba4 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here +// There wont be an error warning shown, it will show 3 request. const num = 103; @@ -15,10 +16,27 @@ 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 +/* +The last digit of 42 is 3 +The last digit of 105 is 3 +The last digit of 806 is 3 +*/ // Explain why the output is the way it is // =============> write your explanation here +/* Simply the "const num = 103" is forcing return num to be 103 at all times. + This can be fixed by putting num in getLastDigit(num), removing the "const num = 103" as it isnt needed. // Finally, correct the code to fix the problem // =============> write your new code here +/* +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 diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..97ba4e2190 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + let squaredHeight = (height * height); + let baseBmi = (weight / squaredHeight); + return bmi = Math.round(baseBmi * 10) / 10; +} +console.log (`BMI is ${calculateBMI(70,1.73)}`); + // 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 5b0ef77ad9..883fe9c79a 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,11 @@ // 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 UpperSnake(text) { + let upperCase = text.toUpperCase(); + let snakeCase = upperCase.replaceAll(" ","_"); + return snakeCase; +} + +console.log(UpperSnake("hello there bob")); \ 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 6265a1a703..dfbb772c00 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,8 @@ // 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(weight) { + return (weight * 2.204); +} + +console.log(toPounds(70)) \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..7eee877fbf 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -21,18 +21,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 +// =============> 61 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> "61" // 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, when pad is last called its at ${pad(remainingSeconds)} where the value left is 1 // e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> 1 at const remainingSexonds = seconds % 60 gives 1 \ No newline at end of file