From 1df05b543747ff100a313d6dc86a0f0e5a9d9f93 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Mon, 15 Jun 2026 13:30:32 +0100 Subject: [PATCH 01/12] Key errors sprint 2 0.js 1-key-errors 0.js have spotted --- Sprint-2/1-key-errors/0.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..7a9eb878cf 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,25 @@ -// Predict and explain first... -// =============> write your prediction here -// 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)}`; + let str = '${str[0].toUpperCase()}${str.slice(1)}`; return str; } -// =============> write your explanation here -// =============> write your new code here +It said syntaxError because identifier 'str' has already been declared +because we should use backtick`` to wrap the template literal.The first one of the bracket is a +single quote, not a backtick. + + Also, since str has already been declared as a parameter, we should not use it to define as variable. + + + + + +function capitalise(str) { + + let result = `${str[0].toUpperCase() + str.slice(1)}`; + return result; +} + +console.log(capitalise("str")); + From 4774028a83063803a1d787c3fad3848cd8886ff2 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Mon, 15 Jun 2026 15:08:59 +0100 Subject: [PATCH 02/12] 1.js logic error insides function --- Sprint-2/1-key-errors/1.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..9c0e5ca561 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,10 +1,3 @@ -// Predict and explain first... - -// Why will an error occur when this program runs? -// =============> write your prediction here - -// Try playing computer with the example to work out what is going on - function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; @@ -14,7 +7,19 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +The terminal shows the syntax error because decimal number has been declared. +because the decimal number is a variable which is not supposed to define in the function, +but the decimal number has been defined insides the functon, so it will forever return 50 %. + Also, when we call the fucnton, we should name the function convertToPercentage. + + + +function convertToPercentage(decimalNumber) { + + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.5)); -// Finally, correct the code to fix the problem -// =============> write your new code here From 7a9559b39ec6421837c1732974ca01e2bec87967 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Mon, 15 Jun 2026 15:23:43 +0100 Subject: [PATCH 03/12] 2.js variable num not defined --- Sprint-2/1-key-errors/2.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..d52f46729a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,22 @@ -// 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 function square(3) { return num * num; } -// =============> write the error message here -// =============> explain this error message here + It shows the syntax error which is an unexpected number; + because we should not put 3 insides the variable, because it will lead to variable: num not defined +insides the function, so the 3 doesn't work insides the function. + +We need to put num instead of 3 insides the(); +That way when we call the function by using console.log.The 3 will go into the num variable. + -// Finally, correct the code to fix the problem +function square(num) { + return num * num; +} -// =============> write your new code here From fedf840a0a3c2106f136b1efc09075fad2205ae1 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Mon, 15 Jun 2026 15:59:06 +0100 Subject: [PATCH 04/12] The variable hasn't been defined yet. --- Sprint-2/2-mandatory-debug/0.js | 16 +++++++++++----- Sprint-2/2-mandatory-debug/1.js | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..f59f347333 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,8 @@ -// Predict and explain first... -// =============> write your prediction here +The problem is unexpected identifier "problem" +The problem is the result doesn't print the mulitplication of the number, +because we should not call the function inside the function; + function multiply(a, b) { console.log(a * b); @@ -8,7 +10,11 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +Instead, we should define the expression a * b +and return the expression. + +/ function multiply(a, b) { + return (a * b); + } -// Finally, correct the code to fix the problem -// =============> write your new code here +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); \ 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 37cedfbcfd..2ca9b6c6cf 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ -// Predict and explain first... -// =============> write your prediction here +Unexpected identifier "problem" +variable hasn't been defined so the variable cannot do function. function sum(a, b) { return; @@ -8,6 +8,14 @@ function sum(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 + +because return should be followed by a + b; +the final result doesn't return the value. + + +function sum(a, b) { + return; + a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); From 93486c9bf2e00b1e9d69b1478a1613531f4593f7 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Mon, 15 Jun 2026 22:23:39 +0100 Subject: [PATCH 05/12] global frame and variable --- Sprint-2/2-mandatory-debug/2.js | 37 +++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..2281e71754 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,12 @@ -// Predict and explain first... -// Predict the output of the following code: -// =============> Write your prediction here +The const should not be put into the global frame. +if it is set in the global frame, this will result in a single result:3, +no matter which variables you put in later. + +The variable insides should have num to match the function expression. + + +My prediction of the result will be all in 3. const num = 103; @@ -13,12 +18,22 @@ 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 -// 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 + +yes the output is all in 3, because the reason are above . + + + +... ... ... ... ... ... ... ... ... ... ... ... ... ... ... + +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)}`); + + +After we delete the global frame and put in the variable, we see +the result now shows three different digit number. \ No newline at end of file From 608b21e42e0c8fe89bba724ac0585d9447efd465 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Tue, 16 Jun 2026 16:11:43 +0100 Subject: [PATCH 06/12] define parameter and the function --- Sprint-2/3-mandatory-implement/1-bmi.js | 27 ++++++++++++----------- Sprint-2/3-mandatory-implement/2-cases.js | 10 +++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..9bc97e2820 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -1,19 +1,20 @@ -// Below are the steps for how BMI is calculated -// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. -// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: -// squaring your height: 1.73 x 1.73 = 2.99 -// dividing 70 by 2.99 = 23.41 -// Your result will be displayed to 1 decimal place, for example 23.4. +function calculateBMI(weight, height) { + + let newheight = height / 100; + let num = weight / (newheight ** 2); + let idea = num.toFixed(1); + + return idea; +} + + +console.log(calculateBMI(58, 178)); + + + -// You will need to implement a function that calculates the BMI of someone based off their weight and height -// Given someone's weight in kg and height in metres -// Then when we call this function with the weight and height -// 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 diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..7c30f5334f 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -4,6 +4,16 @@ // UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. // Implement a function that: +function convertToUpperCase(text) { +const result = text.toUpperCase(); +return result; +} + +console.log(convertToUpperCase("hello")); + + + + // Given a string input like "hello there" // When we call this function with the input string From 321fa4869bc9da38d0bc11de2407a162e6e6f2b6 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Sat, 20 Jun 2026 20:35:32 +0100 Subject: [PATCH 07/12] FIlepath. slice --- Sprint-1/1-key-exercises/1-count.js | 1 + Sprint-1/1-key-exercises/2-initials.js | 10 +++++++++- Sprint-1/1-key-exercises/3-paths.js | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..1cb53ace08 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -1,3 +1,4 @@ + let count = 0; count = count + 1; diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..b8b2e5e974 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,15 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; + +function first(firstName, middleName, lastName){ + + let initials = firstName.slice(0,1) + middleName.slice(0,1) + lastName.slice(0,1); + + return `${initials}`; +} +console.log(first(firstName, middleName, lastName)); + // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..4ae6c9e912 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -11,13 +11,15 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); + +// 1. Get the base (file.txt) const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); +const dir = filePath.slice(0, lastSlashIndex); + // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 31950b1d1848fd12ecfb613ecdd8bf8ddd47267e Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Sat, 20 Jun 2026 21:29:06 +0100 Subject: [PATCH 08/12] What does num represent ? --- Sprint-1/1-key-exercises/4-random.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..0cb3c7dce2 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,7 +3,18 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +Math.floor is a function to make sure it is a whole number. + +The fuction will randomly choose a decimal number from 0 - 1. +After that will do the Math(100-1+1) and multiply the decimal value and add 1. + + + + // 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 // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + + + From 522d1c32e979c8e9f53548cf2a193032799646d5 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Sat, 20 Jun 2026 23:04:54 +0100 Subject: [PATCH 09/12] function X(num) --- Sprint-1/2-mandatory-errors/0.js | 5 +++-- Sprint-1/2-mandatory-errors/1.js | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..f2702bcd14 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-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? + diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..60526e41e2 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 - -const age = 33; -age = age + 1; +function X(num){ +const age = num +1; +return age;} +console.log(X(33)); From 7d2dc325995d88921519638d9f469351d4acaeed Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Sat, 20 Jun 2026 23:30:05 +0100 Subject: [PATCH 10/12] .toString --- Sprint-1/2-mandatory-errors/2.js | 6 +++--- Sprint-1/2-mandatory-errors/3.js | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..1cdbd587a9 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? - -console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; +const cityOfBirth = "BOlton"; +const sentence = `I was born in ${cityOfBirth}`; +console.log(sentence); \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..01f7180b71 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,13 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); + +because it doesn't have console.log, so it doesn't print the result. +but it gives the function errors. + +it is not what I expected, because we should change the number into string, because it is not a +function. + // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working From b5540b5b30226ec0ddc2b4774f057f4c23957959 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Sat, 20 Jun 2026 23:47:36 +0100 Subject: [PATCH 11/12] twelvehour, twentyfour --- Sprint-1/2-mandatory-errors/4.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..06c2f6483b 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelvehourClockTime = "8:53pm"; +const twentyfourhourClockTime = "20:53"; + +console.log(twelvehourClockTime); +console.log(twentyfourhourClockTime); + From 5e38349cedcdf0c2e0d0583a2c44b58128fd50ca Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Tue, 30 Jun 2026 10:16:04 +0100 Subject: [PATCH 12/12] clean the accidental Sprint-2 --- Sprint-2/1-key-errors/0.js | 26 +++++----------- Sprint-2/1-key-errors/1.js | 25 ++++++--------- Sprint-2/1-key-errors/2.js | 18 +++++------ Sprint-2/2-mandatory-debug/0.js | 16 +++------- Sprint-2/2-mandatory-debug/1.js | 18 +++-------- Sprint-2/2-mandatory-debug/2.js | 37 +++++++---------------- Sprint-2/3-mandatory-implement/1-bmi.js | 27 ++++++++--------- Sprint-2/3-mandatory-implement/2-cases.js | 10 ------ 8 files changed, 59 insertions(+), 118 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 7a9eb878cf..653d6f5a07 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,25 +1,13 @@ +// Predict and explain first... +// =============> write your prediction here +// 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)}`; + let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -It said syntaxError because identifier 'str' has already been declared -because we should use backtick`` to wrap the template literal.The first one of the bracket is a -single quote, not a backtick. - - Also, since str has already been declared as a parameter, we should not use it to define as variable. - - - - - -function capitalise(str) { - - let result = `${str[0].toUpperCase() + str.slice(1)}`; - return result; -} - -console.log(capitalise("str")); - +// =============> write your explanation here +// =============> write your new code here diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 9c0e5ca561..f2d56151f4 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,25 +1,20 @@ -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; - - return percentage; -} - -console.log(decimalNumber); - -The terminal shows the syntax error because decimal number has been declared. -because the decimal number is a variable which is not supposed to define in the function, -but the decimal number has been defined insides the functon, so it will forever return 50 %. - Also, when we call the fucnton, we should name the function convertToPercentage. +// Predict and explain first... +// Why will an error occur when this program runs? +// =============> write your prediction here +// Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - + const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(convertToPercentage(0.5)); +console.log(decimalNumber); + +// =============> write your explanation here +// Finally, correct the code to fix the problem +// =============> write your new code here diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index d52f46729a..aad57f7cfe 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,22 +1,20 @@ +// 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 function square(3) { return num * num; } +// =============> write the error message here - It shows the syntax error which is an unexpected number; - because we should not put 3 insides the variable, because it will lead to variable: num not defined -insides the function, so the 3 doesn't work insides the function. - -We need to put num instead of 3 insides the(); -That way when we call the function by using console.log.The 3 will go into the num variable. - +// =============> explain this error message here -function square(num) { - return num * num; -} +// Finally, correct the code to fix the problem +// =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index f59f347333..b27511b417 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,8 +1,6 @@ +// Predict and explain first... -The problem is unexpected identifier "problem" -The problem is the result doesn't print the mulitplication of the number, -because we should not call the function inside the function; - +// =============> write your prediction here function multiply(a, b) { console.log(a * b); @@ -10,11 +8,7 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -Instead, we should define the expression a * b -and return the expression. - -/ function multiply(a, b) { - return (a * b); - } +// =============> write your explanation here -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); \ No newline at end of file +// Finally, correct the code to fix the problem +// =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 2ca9b6c6cf..37cedfbcfd 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ -Unexpected identifier "problem" -variable hasn't been defined so the variable cannot do function. +// Predict and explain first... +// =============> write your prediction here function sum(a, b) { return; @@ -8,14 +8,6 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -because return should be followed by a + b; -the final result doesn't return the value. - - -function sum(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 2281e71754..57d3f5dc35 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,12 +1,7 @@ +// Predict and explain first... -The const should not be put into the global frame. -if it is set in the global frame, this will result in a single result:3, -no matter which variables you put in later. - -The variable insides should have num to match the function expression. - - -My prediction of the result will be all in 3. +// Predict the output of the following code: +// =============> Write your prediction here const num = 103; @@ -18,22 +13,12 @@ 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 +// Finally, correct the code to fix the problem +// =============> write your new code here - -yes the output is all in 3, because the reason are above . - - - -... ... ... ... ... ... ... ... ... ... ... ... ... ... ... - -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)}`); - - -After we delete the global frame and put in the variable, we see -the result now shows three different digit number. \ No newline at end of file +// 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 9bc97e2820..17b1cbde1b 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -1,20 +1,19 @@ +// Below are the steps for how BMI is calculated +// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. +// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: -function calculateBMI(weight, height) { - - let newheight = height / 100; - let num = weight / (newheight ** 2); - let idea = num.toFixed(1); - - return idea; -} - - -console.log(calculateBMI(58, 178)); - - - +// squaring your height: 1.73 x 1.73 = 2.99 +// dividing 70 by 2.99 = 23.41 +// Your result will be displayed to 1 decimal place, for example 23.4. +// You will need to implement a function that calculates the BMI of someone based off their weight and height +// Given someone's weight in kg and height in metres +// Then when we call this function with the weight and height +// 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 diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 7c30f5334f..5b0ef77ad9 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -4,16 +4,6 @@ // UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. // Implement a function that: -function convertToUpperCase(text) { -const result = text.toUpperCase(); -return result; -} - -console.log(convertToUpperCase("hello")); - - - - // Given a string input like "hello there" // When we call this function with the input string