Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
23 changes: 0 additions & 23 deletions Sprint-1/1-key-exercises/3-paths.js

This file was deleted.

2 changes: 0 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js

This file was deleted.

2 changes: 0 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js

This file was deleted.

22 changes: 0 additions & 22 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js

This file was deleted.

18 changes: 13 additions & 5 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// Predict and explain first...
// =============> write your prediction here
//I think it will give an error because we have `str` twice in line 10 we should only have return without `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;
}
// function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
// }

// =============> write your explanation here
// =============> write your new code here
// The error happened because 'str' was declared twice, once as a parameter and once with 'let' inside the function.
// Also, when calling the function, using a word without quotes caused a ReferenceError.
// After removing the duplicate declaration and passing a string with quotes, the function works correctly,
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}
console.log(capitalise("Hard"));
20 changes: 12 additions & 8 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// 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
// =============> write your prediction here

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
// the error occur because the decimalNumber has already been declared.

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

return percentage;
}

console.log(decimalNumber);

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

// I tried to run the code it gives me SyntaxError,that the decimalNumber has already been declared, we can see in the parameter already has name decimalNumber.
// thats why declaring it again inside the function, causes an errors.

// 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));
17 changes: 10 additions & 7 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
//I think it will give an error because the function parameter can not be a number like (3).

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

// =============> write the error message here
// =============> write the error message here
// SyntaxError: Unexpected number

// =============> explain this error message here

// Finally, correct the code to fix the problem
// the parameter can't be a number like (3),also changing num * num to number instead to match the parameter.
// Finally, correct the code to fix the problem.

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



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

// =============> write your prediction here

function multiply(a, b) {
console.log(a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
// in console.log we should just write (multiply(10,32) because writing in plain english will give us an error,
// and it won't give the output.

// =============> write your explanation here
// the code was broken because the console.log was inside the function it not a function,by using the return it gives the outupt


// Finally, correct the code to fix the problem
// =============> write your new code here
function multiply(a, b) {
return (a * b)
}

console.log(multiply(10, 32));
15 changes: 9 additions & 6 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Predict and explain first...
// =============> write your prediction here
// The return statement is not in the right place, so the function doesn’t return the value.

function sum(a, b) {
return;
a + b;
}
// =============> write your explanation here

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
// The return statement is stopping the function too early, so it doesn’t return a + b.

// =============> write your explanation here
// 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)}`);
32 changes: 25 additions & 7 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@
// Predict the output of the following code:
// =============> Write your prediction here

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
// 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
// we will always get number 3 because num is 103 in the last digit of it is 3.

// 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
// We need num in the function as a parameter.
7 changes: 6 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
let BMI = weight / (height * height);
let rounded = Math.round(BMI * 10) / 10;
Comment on lines +18 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you notice the variables rounded and BMI are rendered in different colors?

Many IDEs and viewers that support syntax highlighting (including GitHub) display identifiers in different formats and colors.

let bmi, camelCase;
let Bmi, PascalCase;
let BMI, UPPER_SNAKE_CASE;

Can you look up the naming conventions in JavaScript? In particular,

  • Variable and function names
  • Class and Types names
  • Named constants

Then, update the variable names according to those conventions.


On separate note, it is a good practice to declare a "variable" using const instead of let when the variable is not going to be reassigned a value.

return rounded;

}
console.log(calculateBMI(70, 1.73));
// return the BMI of someone based off their weight and height
}
8 changes: 8 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,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 toUpperSnakeCase(inputString) {
return inputString.replaceAll(" ", "_").toUpperCase();


}
console.log(toUpperSnakeCase("hello there"));
console.log (toUpperSnakeCase("lord of the rings"));
24 changes: 24 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,27 @@
// 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 (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}`;
}
Comment on lines +7 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation of the code is a bit off.

Suggestion: You can use this VSCode feature to auto indent JS code.
https://code.visualstudio.com/docs/languages/javascript#_formatting

console.log (toPounds("399p"));
console.log (toPounds("400p"));
console.log (toPounds("243p"));
console.log (toPounds("9876p"));
console.log (toPounds("18p"));
7 changes: 7 additions & 0 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@ function formatTimeDisplay(seconds) {

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// It will be called 3 times hours,minutes and Seconds.

// 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
// The first argument passed to pad (totalHours).
// totalHours = 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// pad (totalHours) = pad(0) returns "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 pad called last time is num = 1 because that's the remainingSeconds which is 1 after
// we 61 divided by 60 = 1.

// 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 will be 01 because ToString gives "1" and padStart("2, 0") that adds 0 in the front
4 changes: 4 additions & 0 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
console.log(formatAs12HourClock("08:00"));
console.log(formatAs12HourClock("23:00"));
console.log(formatAs12HourClock("00:00"));
console.log(formatAs12HourClock("12:00"))