Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
53f9188
new work space in vscode
Abrsh100 Oct 11, 2025
a825bf7
correctin and updating the exercise
Abrsh100 Oct 13, 2025
d873260
Answering each question with in the file by puting // to separate fro…
Abrsh100 Oct 15, 2025
872131a
solution for sprint 2
Abrsh100 Oct 25, 2025
d139163
Delete Sprint-1/1-key-exercises/1-count.js
Abrsh100 Oct 26, 2025
14f6ab7
Delete Sprint-1/1-key-exercises/2-initials.js
Abrsh100 Oct 26, 2025
3ea986c
Delete Sprint-1/1-key-exercises/3-paths.js
Abrsh100 Oct 26, 2025
7688edc
Delete Sprint-1/2-mandatory-errors/0.js
Abrsh100 Oct 26, 2025
a00d344
Delete Sprint-1/1-key-exercises/4-random.js
Abrsh100 Oct 26, 2025
d336e24
Delete Sprint-1/2-mandatory-errors/1.js
Abrsh100 Oct 26, 2025
5b0207b
Delete Sprint-1/2-mandatory-errors/2.js
Abrsh100 Oct 26, 2025
73b25cc
Delete Sprint-1/2-mandatory-errors/3.js
Abrsh100 Oct 26, 2025
3c5555c
Delete Sprint-1/3-mandatory-interpret/1-percentage-change.js
Abrsh100 Oct 26, 2025
920fa0f
Delete Sprint-1/2-mandatory-errors/4.js
Abrsh100 Oct 26, 2025
eb5face
Delete Sprint-1/3-mandatory-interpret/2-time-format.js
Abrsh100 Oct 26, 2025
f3f4e0b
Delete Sprint-1/3-mandatory-interpret/3-to-pounds.js
Abrsh100 Oct 26, 2025
8448e94
restor sprint 1 from cyf main
Abrsh100 Oct 27, 2025
76ab3c7
correcting the errors based on your valuable comments
Abrsh100 Oct 29, 2025
644248f
communicating the valuable comments
Abrsh100 Oct 30, 2025
ae53e31
changing firstLetter with str
Abrsh100 Oct 31, 2025
f4a96ca
correcting some typos
Abrsh100 Nov 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
// Predict and explain first...
// =============> write your prediction here

// The code will capitalize the first word of the str which gives "Str"

// 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;
}
// The error occurs in line 13 and it says "SyntaxError: Identifier 'str' has already been declared"
// The error is informing us that the string str has already been declared in line 12 so we can not declare it again.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the string str

Calling str a "string" isn’t quite right. Try using a term that describes it as a name rather than a value.
Accurate terminology is essential for clear communication and precise reasoning about how code works.


//function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
//}

// =============> write your explanation here

// The code is written to capitalize the first letter of str which is expected to give the result Str.

// =============> write your new code here

function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
console.log(capitalise("str"))
16 changes: 13 additions & 3 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
// This code is tend to be a code to convert decimal number in to %. I predict there will be an error because the call for the function has a bug.

// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
/*function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}
}/

console.log(decimalNumber);
console.log(decimalNumber);*/

// =============> write your explanation here
// A syntaxError has been observed because the decimalNumber is already declared.
// if we delete line 10 anther error happen this time about calling the function in which decimalNumber is not defined in the global scope.

// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(convertToPercentage("0.5"));
11 changes: 10 additions & 1 deletion Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
/* There is a problem in the function parameter. we can not use number in parameter.
even though line 12 by it self has no coding problem but the num is not declared before.*/

/*
function square(3) {
return num * num;
}
*/

// =============> write the error message here

/* unexpected number
// =============> explain this error message here
we can not use number in a parameter so 3 is not used as identifier */

// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num * num;
}
console.log(square("3"))


11 changes: 9 additions & 2 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// Predict and explain first...

// =============> write your prediction here
/*the function doesn't return any thing so there will be an error. */

function multiply(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
/* As predicted the function does not return any thing. But the first call gives 320. and the second undefine. */

// 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)}`);
13 changes: 10 additions & 3 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Predict and explain first...
// =============> write your prediction here
/* The code will give us the sum of 10 and 32 which will be " The sum of 10 and 32 is 42" */

function sum(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
/* the call of the function gives undefine result. the reason for this is the semicolon after return which shouldn't be placed there.
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============> write your new code here */
function sum(a, b) {
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
20 changes: 18 additions & 2 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

// Predict the output of the following code:
// =============> Write your prediction here
/* I predict that the three call are giving
The last digit of 42 is 2
The last digit of 105 is 5
The last digit of 806 is 6 */

const num = 103;
/*const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
Expand All @@ -12,13 +16,25 @@ function getLastDigit() {
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
/* 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
/* because the num is determined at fires and 103 is given to the num. as a result we see the same result.*/
// 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
7 changes: 5 additions & 2 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// 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) {
function calculateBMI(weight, height) {
const bmi= weight/ (height*height)
return bmi.toFixed(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?

Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example,

  console.log(123);              // Output 123
  console.log("123");            // Output 123
  
  // Treated differently in the program
  let sum1 = 123 + 100;         // Evaluate to 223 -- a number
  let sum 2 = "123" + 100;      // Evaluate to "123100" -- a string.

// return the BMI of someone based off their weight and height
}
}
console.log(calculateBMI(86,1.70));
6 changes: 6 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
// 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 toUpperCase(text) {
return text.toUpperCase();
}

console.log(toUpperCase("hello there"));
console.log(toUpperCase("lord of the ring"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this output LORD_OF_THE_RINGS?

11 changes: 11 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@
// 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(pennies) {
Copy link
Contributor

@cjyuan cjyuan Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter value is expected to be a string in the form "399p" (a sting with a trailing 'p').

const pounds = pennies / 100;
return pounds.toFixed(2);
}

// calling the function to make sure it works
console.log(toPounds(32391));
console.log(toPounds(3239));
console.log(toPounds(323));
console.log(toPounds(32));
console.log(toPounds(3));
6 changes: 6 additions & 0 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,17 +19,22 @@ function formatTimeDisplay(seconds) {

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
/* pad will be called 3 times. one for totalHours, one for remainingMinutes and one for remainingSeconds.*/

// 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
/* when I run the code the result is 00:01:01 there for the value assigned to num is "0".

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
/* the return value is "00". this comes 0 changed to string and then padstart(2,0) changes it to "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
/* The value assigned to num when the pad is called for the last time is "1". */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A notation like "1" (a value enclosed by a pair of double quotes) is conventionally used to suggest the value is a string.

So use of double quotes on "00" in the previous question is good. But for a number-type value, use of double quotes could be misleading.


// 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
/* The return value is 1. The code 1.toString() changes the num 1 to string "1" then the code .padStart(2, "0"); changes "1" to "01" */
22 changes: 21 additions & 1 deletion Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours===0) {
return`12:00 am`
}
if (hours===12) {
return `12:00 pm`
}
if (hours > 12) {
return `${hours - 12}:00 pm`;
}
return `${time} am`;
if (hours > 0 && hours < 12)
return `${String(hours).padStart(2, "0")}:00 am`;
}
Comment on lines 5 to 11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your function return the value you expected from each of the following function calls?

  • formatAs12HourClock("00:31")
  • formatAs12HourClock("12:31")
  • formatAs12HourClock("01:31")
  • formatAs12HourClock("13:31")


const currentOutput = formatAs12HourClock("08:00");
Expand All @@ -22,4 +29,17 @@ const targetOutput2 = "11:00 pm";
console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`

);
const currentOutput3 = formatAs12HourClock("00:00");
const targetOutput3 = "12:00 am";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
const currentOutput4 = formatAs12HourClock("12:00");
const targetOutput4 = "12:00 pm";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);