From 2b3cebc48019b437af6a7a7a167148eb5d148895 Mon Sep 17 00:00:00 2001 From: aida eslami Date: Sun, 8 Jun 2025 23:49:53 +0100 Subject: [PATCH 01/11] Key-Exercises --- Sprint-1/1-key-exercises/1-count.js | 5 +++++ Sprint-1/1-key-exercises/2-initials.js | 10 +++++++++- Sprint-1/1-key-exercises/4-random.js | 11 +++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..e0be3d795 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,8 @@ count = count + 1; // 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 + + + +//ANSWER: +// Take the current value of count, add 1 to it, and store the result back in count. \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..0b1a04247 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 = ``; + // https://www.google.com/search?q=get+first+character+of+string+mdn + + + +//ANSWER: + +let initials = firstName[0]+' ' + middleName[0] +' ' + lastName[0]; + + console.log(initials); \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..9ef1c5be6 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,19 @@ const minimum = 1; const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +console.log(num) + + // 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 + + +//ANSWER: + +//Math.random() : Gives a decimal between 0 and 1 +//Multiply by 100 : Now it's between 0 and 100 +//Math.floor() : Turns it into a whole number (0–99) +//Add 1 : Now it's between 1–100 From b0c4234568dfb72d3b0f4171496dcb02cb6cc830 Mon Sep 17 00:00:00 2001 From: aida eslami Date: Mon, 9 Jun 2025 00:50:39 +0100 Subject: [PATCH 02/11] Mandatory-errors --- Sprint-1/2-mandatory-errors/0.js | 6 ++++-- Sprint-1/2-mandatory-errors/1.js | 13 +++++++++++-- Sprint-1/2-mandatory-errors/2.js | 11 ++++++++++- Sprint-1/2-mandatory-errors/3.js | 15 +++++++++++++-- Sprint-1/2-mandatory-errors/4.js | 12 ++++++++++-- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..3030ce824 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ -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? + +//ANSWER : Add // ( CTRL + /) \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..5eeecc5f1 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,13 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; -age = age + 1; +//const age = 33; +//age = age + 1; + + + +//ANSWER : age is a const variable and we can not reassign it. We can change it to let like: + + +let age =33; +age=age+1; +console.log(age) \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..9b7c4c997 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,14 @@ // 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}`); +// console.log(`I was born in ${cityOfBirth}`); +// const cityOfBirth = "Bolton"; + + +// ANSWER : We should put cityOfBirth before using it in a code. + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + + + diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..1037ae9e7 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +// const cardNumber = 4533787178994213; +// const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +7,14 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + + + +// ANSWER : Code is not working because Slice() function is for STRING and we should convert number to string and then ask for last 4 digits. + + +const cardNumber = 4533787178994213; +let last4Digits = cardNumber.toString() +last4Digits=last4Digits.slice(-4) + +console.log(last4Digits) \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..1388bf6cd 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,10 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// const 12HourClockTime = "20:53"; +// const 24hourClockTime = "08:53"; + + +//ANSWER: variable should not start with number + +const HourClock24 = "20:53"; +const HourClock12= "08:53"; + +console.log("The time is: "+HourClock12 + " or",HourClock24) \ No newline at end of file From 4c52251f9d05dfbfddaef1bd44c910cd3d12b656 Mon Sep 17 00:00:00 2001 From: aida eslami Date: Mon, 9 Jun 2025 23:50:03 +0100 Subject: [PATCH 03/11] Mandatory-interpret --- .../1-percentage-change.js | 26 ++++++++++++++++- .../3-mandatory-interpret/2-time-format.js | 18 +++++++++++- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 28 +++++++++++-------- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..257932337 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -20,3 +20,27 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + + + +// ANSWER : + +// A: totally 7 times: +// 3 times replaceAll() , 3 times Number() , 1 time console.log + + +// B: Missing comma between 2 arguments of replaceAll () function + + +// C: +// carPrice = Number(carPrice.replaceAll(",", "")); +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + + +// D: +// let carPrice = "10,000"; +// let priceAfterOneYear = "8,543"; +// const priceDifference = carPrice - priceAfterOneYear; +// const percentageChange = (priceDifference / carPrice) * 100; + +//E: At first it remove the comma and then convert it to Integer diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..d8008540e 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 3600; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -23,3 +23,19 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + + + + +// ANSWER +// A : Totally 6 + +// B: Just 1 , console.log(result); + +// C: % is a remainder operator. It gives the remainder when movieLength is divided by 60. + +// D: How many minutes are in this movie. + +// E: It shows the time of movie in this style :---> HH:MM:SS + +//F: Yes it works, I tried different movie length in seconds. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..37a7136d5 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,21 +1,24 @@ -const penceString = "399p"; +const penceString = "39867p"; +//create a variable with this value -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); +const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1); +// removes the 'p' from the end of the string const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); +// makes sure the number has at least 3 digits by adding 0 at the start if needed + + +const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); +//takes all digits except the last 2 as the pounds--> ???.00 + + + +const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); +// takes the last 2 digits as the pence, adds 0 at the end if it's only 1 digit -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); console.log(`£${pounds}.${pence}`); +//print £pounds.pence // This program takes a string representing a price in pence // The program then builds up a string representing the price in pounds @@ -25,3 +28,4 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + From d518c0c2983609d6356617deb959188ac6f3bd2c Mon Sep 17 00:00:00 2001 From: aida eslami Date: Tue, 10 Jun 2025 01:12:05 +0100 Subject: [PATCH 04/11] Stretch & Key exercise num 3 --- Sprint-1/1-key-exercises/3-paths.js | 8 ++++++-- Sprint-1/4-stretch-explore/chrome.md | 9 +++++++++ Sprint-1/4-stretch-explore/objects.md | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..e3aa065c6 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,11 @@ console.log(`The base part of ${filePath} is ${base}`); // 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 = ; +const dir = filePath.slice(0, lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".")); + + +console.log(`Dir: ${dir}`); +console.log(`Ext: ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..13aacdbf1 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,17 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? + Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? + + What is the return value of `prompt`? + + + + \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..d1ce958eb 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -6,11 +6,28 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? + + Now enter just `console` in the Console, what output do you get back? + Try also entering `typeof console` + Answer the following questions: What does `console` store? +It is a JavaScript object with methods for showing output and debugging code, like log, warn, error, and assert. + + + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + + + + +what does the `.` mean? + + \ No newline at end of file From 73cd2e5a081a086f523088189251aa226e9198db Mon Sep 17 00:00:00 2001 From: aida eslami Date: Wed, 11 Jun 2025 15:18:18 +0100 Subject: [PATCH 05/11] Sprint2 /Key Error --- Sprint-2/1-key-errors/0.js | 21 ++++++++++++++++----- Sprint-2/1-key-errors/1.js | 32 ++++++++++++++++++++++++-------- Sprint-2/1-key-errors/2.js | 17 ++++++++++++----- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..20b7bc25a 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,24 @@ // Predict and explain first... -// =============> write your prediction here +// =============> ANSWER +// It takes a string and change its first letter to capitial letter aida -----> Aida // 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; +// } + +// // =============> ANSWER +// SyntaxError: Identifier 'str' has already been declared +// It is not allow to redeclare the parameter str inside the function + +// // =============> write your new code here +let name = "aida"; + function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; + return `${str[0].toUpperCase()}${str.slice(1)}`; } -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise("aida")); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..ec4a2b7c1 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,36 @@ // Predict and explain first... +// =============> ANSWER +// convertToPercentage function takes a number and multiplaited it to 100,to give the percentage and then return it. +// but it doesn't work because we did'nt call it in the main part. +// Also we can not declare a variable which has been declared already // Why will an error occur when this program runs? -// =============> write your prediction here +// we can not declare a variable which has been declared already +// SyntaxError: Identifier 'decimalNumber' has already been declared // 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 +// =============> ANSWER +// It doesn't work because we did'nt call the function. // Finally, correct the code to fix the problem + // =============> write your new code here + +const decimalNumber = 0.5; +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(decimalNumber)); diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..b9c2aa7b9 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,27 @@ - -// Predict and explain first BEFORE you run any code... +// This function does'nt work because we can not set literal value as a parameter. // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// An error for number instead of parameter -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 +// JavaScript is expecting a variable name (parameter) not a literal value // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(5)); From c7bbe5da3641835d3d50e13c1487b945d7d828fb Mon Sep 17 00:00:00 2001 From: aida eslami Date: Wed, 11 Jun 2025 15:30:26 +0100 Subject: [PATCH 06/11] Mandatory-debug --- Sprint-2/2-mandatory-debug/0.js | 17 ++++++++++++---- Sprint-2/2-mandatory-debug/1.js | 21 ++++++++++++++------ Sprint-2/2-mandatory-debug/2.js | 35 +++++++++++++++++++++++++-------- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..041332654 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,23 @@ // Predict and explain first... +// function should multiply a by b and print the answer. and it DOESN'T return . +// So in the Console.log we don't have the result. // =============> write your prediction here -function multiply(a, b) { - console.log(a * b); -} +// function multiply(a, b) { +// console.log(a * b); +// } -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// we don't have result for function because there is no return in function . "The result of multiplying 10 and 32 is undefined" // 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 37cedfbcf..d2e600991 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,22 @@ // Predict and explain first... // =============> write your prediction here +// The code doesn't work because the expression a + b comes after the return statement +// Once the compiler reaches return it exit the function. +// There is no error. we just don't have answer +// function sum(a, b) { +// return; +// a + b; +// } -function sum(a, b) { - return; - a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// There is no error. we just do not have correct answer.===> The sum of 10 and 32 is undefined // 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)}`); diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..5e07a7b78 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,43 @@ // Predict and explain first... -// Predict the output of the following code: // =============> Write your prediction here +// This code should return the last digit of each number but again it doesn't return a correct number because it ask to slice(-1) of "num" +// Predict the output of the following code: +// 3 +// 3 +// 3 -const num = 103; +// const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +// 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)}`); +// 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 +// 3 3 3 // Explain why the output is the way it is +// + // =============> write your explanation here +// because we didn't send our parameter to function. + // Finally, correct the code to fix the problem // =============> write your new code here +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)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem From af0409e07005f18746f83bdafd55b073c54c3d13 Mon Sep 17 00:00:00 2001 From: aida eslami Date: Wed, 11 Jun 2025 17:46:21 +0100 Subject: [PATCH 07/11] Mandatory-implement --- Sprint-2/3-mandatory-implement/1-bmi.js | 10 ++++-- Sprint-2/3-mandatory-implement/2-cases.js | 8 +++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 33 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..82f029b36 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,11 @@ // 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 squaredHeight = height * height; + let BMI = weight / squaredHeight; + BMI = Number(BMI.toFixed(1)); + return BMI; +} +let result = calculateBMI(70, 1.73); + +console.log(`The BMI for a person weighing 70kg and 1.73m tall is ${result}`); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..806ef19fb 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 UPPER_SNAKE_CASE(NewWord) { + let UpperWord = NewWord.toUpperCase(); + let result = UpperWord.replaceAll(" ", "_"); + return result; +} + +console.log(UPPER_SNAKE_CASE("hello aida hope you are well")); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..67f227695 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,36 @@ // 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 + +const penceString = 0; +function toPounds(penceString) { + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + return { pounds, pence }; +} + +for (let i = 0; i < 5; i++) { + let randomNumber = Math.floor(Math.random() * 100001); + + PenceRandom = randomNumber + "p"; + + let result = toPounds(PenceRandom); + + console.log( + `Random: ${randomNumber}p → Pounds: £${result.pounds}.${result.pence}` + ); +} From d13a01a3080212ade08ceb471a993c88ba4d22b3 Mon Sep 17 00:00:00 2001 From: aida eslami Date: Wed, 11 Jun 2025 19:06:55 +0100 Subject: [PATCH 08/11] Mandatory-Interpret --- Sprint-2/4-mandatory-interpret/time-format.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..40587a116 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -10,6 +10,7 @@ function formatTimeDisplay(seconds) { 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,23 @@ 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 +// =============> It is 0 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> it is 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 +// =============> It is 1 +// The last time pad() is called, it's for the seconds value. Since remainingSeconds = 1, num is assigned 1. +// pad(1) returns "01" to format the time as hh:mm:ss // 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 +//The last call to pad() formats the seconds. +// remainingSeconds is 1, so pad(1) is called.Inside pad, 1 becomes "1" (string), and since it's a single digit, it's padded to "01". +// So the return value is "01". From 54b19d6d77858a0958dc570f119cd8ce1ee860ed Mon Sep 17 00:00:00 2001 From: aida eslami Date: Wed, 11 Jun 2025 20:16:43 +0100 Subject: [PATCH 09/11] Stretch-extend --- Sprint-2/5-stretch-extend/format-time.js | 55 ++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..860038b90 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,15 +3,29 @@ // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + const [hourStr, minuteStr] = time.split(":"); + let hours = Number(hourStr); + let suffix = "am"; + + if (hours === 0) { + hours = 12; + } else if (hours === 12) { + suffix = "pm"; + } else if (hours > 12) { + hours -= 12; + suffix = "pm"; } - return `${time} am`; + + const formattedHour = String(hours).padStart(2, "0"); + return `${formattedHour}:${minuteStr} ${suffix}`; } const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; +console.log( + `The current time is 08:00 in 24-hour style, and this is ${targetOutput} in 12-hour style.` +); + console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` @@ -19,7 +33,40 @@ console.assert( const currentOutput2 = formatAs12HourClock("23:00"); const targetOutput2 = "11:00 pm"; +console.log( + `The current time is 23:00 in 24-hour style, and this is ${targetOutput2} in 12-hour style.` +); console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("00:00"); +const targetOutput3 = "12:00 am"; +console.log( + `The current time is 00:00 in 24-hour style, and this is ${targetOutput3} in 12-hour style.` +); +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("13:40"); +const targetOutput4 = "01:40 pm"; +console.log( + `The current time is 13:40 in 24-hour style, and this is ${targetOutput4} in 12-hour style.` +); +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("22:15"); +const targetOutput5 = "10:15 pm"; +console.log( + `The current time is 22:15 in 24-hour style, and this is ${targetOutput5} in 12-hour style.` +); +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); From 5c0ad59e4c7f85d656b71b65f5387f1f127c2c67 Mon Sep 17 00:00:00 2001 From: Aida Eslami Date: Sat, 28 Jun 2025 12:51:03 +0100 Subject: [PATCH 10/11] trial --- Sprint-1/1-key-exercises/1-count.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index e0be3d795..117bcb2b6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,8 +4,3 @@ count = count + 1; // 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 - - - -//ANSWER: -// Take the current value of count, add 1 to it, and store the result back in count. \ No newline at end of file From 28dff55bc9b045500daf60048ae081b4f9a938c9 Mon Sep 17 00:00:00 2001 From: Aida Eslami Date: Sat, 28 Jun 2025 12:53:41 +0100 Subject: [PATCH 11/11] sprint 1 removed --- Sprint-1/1-key-exercises/2-initials.js | 10 +------ Sprint-1/1-key-exercises/3-paths.js | 8 ++---- Sprint-1/1-key-exercises/4-random.js | 11 -------- Sprint-1/2-mandatory-errors/0.js | 6 ++-- Sprint-1/2-mandatory-errors/1.js | 13 ++------- Sprint-1/2-mandatory-errors/2.js | 11 +------- Sprint-1/2-mandatory-errors/3.js | 15 ++-------- Sprint-1/2-mandatory-errors/4.js | 12 ++------ .../1-percentage-change.js | 26 +---------------- .../3-mandatory-interpret/2-time-format.js | 18 +----------- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 28 ++++++++----------- Sprint-1/4-stretch-explore/chrome.md | 9 ------ Sprint-1/4-stretch-explore/objects.md | 17 ----------- 13 files changed, 26 insertions(+), 158 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 0b1a04247..47561f617 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,15 +5,7 @@ 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 = ``; // https://www.google.com/search?q=get+first+character+of+string+mdn - - - -//ANSWER: - -let initials = firstName[0]+' ' + middleName[0] +' ' + lastName[0]; - - console.log(initials); \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index e3aa065c6..ab90ebb28 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,11 +17,7 @@ console.log(`The base part of ${filePath} is ${base}`); // 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 = filePath.slice(0, lastSlashIndex); +const dir = ; +const ext = ; -const ext = base.slice(base.lastIndexOf(".")); - - -console.log(`Dir: ${dir}`); -console.log(`Ext: ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 9ef1c5be6..292f83aab 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,19 +2,8 @@ const minimum = 1; const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -console.log(num) - - // 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 - - -//ANSWER: - -//Math.random() : Gives a decimal between 0 and 1 -//Multiply by 100 : Now it's between 0 and 100 -//Math.floor() : Turns it into a whole number (0–99) -//Add 1 : Now it's between 1–100 diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index 3030ce824..cf6c5039f 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,4 +1,2 @@ -//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? - -//ANSWER : Add // ( CTRL + /) \ 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? \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 5eeecc5f1..7a43cbea7 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,13 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -//const age = 33; -//age = age + 1; - - - -//ANSWER : age is a const variable and we can not reassign it. We can change it to let like: - - -let age =33; -age=age+1; -console.log(age) \ No newline at end of file +const age = 33; +age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 9b7c4c997..e09b89831 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,14 +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"; - - -// ANSWER : We should put cityOfBirth before using it in a code. - -const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); - - - +const cityOfBirth = "Bolton"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 1037ae9e7..ec101884d 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ -// const cardNumber = 4533787178994213; -// const last4Digits = cardNumber.slice(-4); +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,14 +7,3 @@ // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value - - - -// ANSWER : Code is not working because Slice() function is for STRING and we should convert number to string and then ask for last 4 digits. - - -const cardNumber = 4533787178994213; -let last4Digits = cardNumber.toString() -last4Digits=last4Digits.slice(-4) - -console.log(last4Digits) \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 1388bf6cd..21dad8c5d 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,10 +1,2 @@ -// const 12HourClockTime = "20:53"; -// const 24hourClockTime = "08:53"; - - -//ANSWER: variable should not start with number - -const HourClock24 = "20:53"; -const HourClock12= "08:53"; - -console.log("The time is: "+HourClock12 + " or",HourClock24) \ No newline at end of file +const 12HourClockTime = "20:53"; +const 24hourClockTime = "08:53"; \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 257932337..e24ecb8e1 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -20,27 +20,3 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? - - - -// ANSWER : - -// A: totally 7 times: -// 3 times replaceAll() , 3 times Number() , 1 time console.log - - -// B: Missing comma between 2 arguments of replaceAll () function - - -// C: -// carPrice = Number(carPrice.replaceAll(",", "")); -// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); - - -// D: -// let carPrice = "10,000"; -// let priceAfterOneYear = "8,543"; -// const priceDifference = carPrice - priceAfterOneYear; -// const percentageChange = (priceDifference / carPrice) * 100; - -//E: At first it remove the comma and then convert it to Integer diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index d8008540e..47d239558 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 3600; // length of movie in seconds +const movieLength = 8784; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -23,19 +23,3 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer - - - - -// ANSWER -// A : Totally 6 - -// B: Just 1 , console.log(result); - -// C: % is a remainder operator. It gives the remainder when movieLength is divided by 60. - -// D: How many minutes are in this movie. - -// E: It shows the time of movie in this style :---> HH:MM:SS - -//F: Yes it works, I tried different movie length in seconds. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 37a7136d5..60c9ace69 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,24 +1,21 @@ -const penceString = "39867p"; -//create a variable with this value +const penceString = "399p"; -const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1); -// removes the 'p' from the end of the string +const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 +); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -// makes sure the number has at least 3 digits by adding 0 at the start if needed - - -const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); -//takes all digits except the last 2 as the pounds--> ???.00 - - - -const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); -// takes the last 2 digits as the pence, adds 0 at the end if it's only 1 digit +const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 +); +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); console.log(`£${pounds}.${pence}`); -//print £pounds.pence // This program takes a string representing a price in pence // The program then builds up a string representing the price in pounds @@ -28,4 +25,3 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" - diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index 13aacdbf1..e7dd5feaf 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,17 +11,8 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? - Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? - - What is the return value of `prompt`? - - - - \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index d1ce958eb..0216dee56 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -6,28 +6,11 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? - - Now enter just `console` in the Console, what output do you get back? - Try also entering `typeof console` - Answer the following questions: What does `console` store? -It is a JavaScript object with methods for showing output and debugging code, like log, warn, error, and assert. - - - What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? - - - - -what does the `.` mean? - - \ No newline at end of file