Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4fdac8d
Added hello_world and facts, Practiced console.log
leigh-ross Sep 14, 2026
e986963
Added file, decalred varible
leigh-ross Sep 15, 2026
da52a82
Added file, decalred varible
leigh-ross Sep 15, 2026
21c1378
practicing variables
leigh-ross Sep 15, 2026
24565bc
Practice comparing values
leigh-ross Sep 15, 2026
6aa92d2
Practice if statement
leigh-ross Sep 15, 2026
b49b6c9
Password checker task
leigh-ross Sep 15, 2026
dc179bb
Practice identifying and explaining errors
leigh-ross Sep 16, 2026
f77cdce
Explained variable reassignment.
leigh-ross Sep 16, 2026
1a46297
Getting the first char of a string
leigh-ross Sep 16, 2026
c67e10a
Explain code exercise
leigh-ross Sep 16, 2026
8d45e6f
Slice exercise
leigh-ross Sep 16, 2026
5125f87
Comment practice
leigh-ross Sep 17, 2026
d1b3b63
Var reassignment error handling
leigh-ross Sep 17, 2026
ec4411e
Assign var before print
leigh-ross Sep 17, 2026
aaecbb4
Splice works with strings not numbers
leigh-ross Sep 17, 2026
6d0e108
Var name cannot start with a number
leigh-ross Sep 17, 2026
8e8a147
Answered questions
leigh-ross Sep 17, 2026
dcb8312
Added error back in
leigh-ross Sep 17, 2026
0dfc659
Answered questions
leigh-ross Sep 17, 2026
e574bb5
Answered questions
leigh-ross Sep 17, 2026
e339abe
Explained what each step in the code does
leigh-ross Sep 17, 2026
7d2bbe6
Practice using chrome console
leigh-ross Sep 21, 2026
656d965
Learning objects in JS
leigh-ross Sep 21, 2026
82a1922
Merge branch 'coursework/sprint-2' of https://github.com/leigh-ross/M…
leigh-ross Sep 21, 2026
b492e02
remove prep files from coursework branch
leigh-ross Sep 21, 2026
42e81a7
Replace all function fixed
leigh-ross Sep 23, 2026
bb1e2e0
Fixed dir and ext calculation
leigh-ross Sep 23, 2026
4fef432
Changed movielength to og value
leigh-ross Sep 23, 2026
5f75bcf
Predicted, explained and fixed the error
leigh-ross Sep 23, 2026
194c793
Added original code and moved my code to end
leigh-ross Sep 23, 2026
ac1886b
Predicted, explained and fixed the code errors.
leigh-ross Sep 23, 2026
cd6e897
Predicted, explained and fixed code errors
leigh-ross Sep 23, 2026
689ea33
Predicted, explained and fixed code errors
leigh-ross Sep 23, 2026
cf34a26
Predicted, explained and fixed code errors
leigh-ross Sep 23, 2026
595728f
Predicted, explained and fixed code errors
leigh-ross Sep 23, 2026
3c8783e
BMI calculator function
leigh-ross Sep 23, 2026
0b6a121
Upper case and underscore conversion of strings
leigh-ross Sep 23, 2026
a680b43
Conversion function from sprint 2, to-pounds
leigh-ross Sep 23, 2026
7277b60
Answered questions, rem calculations
leigh-ross Sep 23, 2026
388daad
Added test cases, in process of fixing code
leigh-ross Sep 23, 2026
47508e8
Reset Sprint-2 to match main
leigh-ross Sep 23, 2026
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
27 changes: 23 additions & 4 deletions Sprint-3/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// Predict and explain first...
// =============> write your prediction here
// capitalise function takes 1 str arg
// let srting will give an error if i try to pass my string.
// remove let
// str is being put in template literal
// str[0]: 1st index of str becomes uppercase
// str.slice(1): 2nd index slice until end of str
// str = "frankocean"
// return = "Frankocean"


// 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
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// I was right, error given is because of let str within the function.
// SyntaxError: Identifier 'str' has already been declared
// We cannot have two declarations of the same variable so we remove the let inside .capitalise.
// =============> write your new code here
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
console.log(capitalise("frankocean"))
26 changes: 20 additions & 6 deletions Sprint-3/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
// decimalNumber declared inside the function, this is the value that must be an arg
// line 17 also fails because it tries to access a var that is declared within the function

// 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
// Remove the local var declaration
// ReferenceError: decimalNumber is not defined | console.log(decimalNumber);
// define decimalNumber in line 17 by passing the function with decimalNumber value
// remove the definition in line 11

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

// =============> write your prediction of the error here
// Error because 3 is a value, functions take parameters(like num).
// It wont work 3 is a number literal and not a name/identifier.

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
// The code was expecting the parameter name but found the number literal =3
// This is why we get the syntax error.

// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num * num;
}


console.log(square(3));
20 changes: 16 additions & 4 deletions Sprint-3/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
// Predict and explain first...

// =============> write your prediction here
// It will print 2 lines:
// (10*32=320) line 1: 320
// line 2: The result of multiplying 10 and 32 is undefined

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
// There are two console.log() being called.
// The one inside the funtion prints the result of the multiplication
// The one outside the function prints the desired result of the whole string but there is no return from the function so it is undefined
// 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)}`);
21 changes: 16 additions & 5 deletions Sprint-3/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// Predict and explain first...
// =============> write your prediction here
// I dont think the code will run at all since the return is separated from the sum that should happen
// the console.log() oustide the function will say the sum is undefined.

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
// The sum of 10 and 32 is undefined
// I was wrong, I thought that the code would not run.
// The output says the sum is undefined because the return statement and the "a + b" are separated by ;
// To fix it, I just need to remove the ; next to return on line 7.
// 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)}`);
35 changes: 28 additions & 7 deletions Sprint-3/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,44 @@

// Predict the output of the following code:
// =============> Write your prediction here
// Nothing is going to run properly because the function does not have any parameters.
// I think everything will get a syntax error

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
// I was wrong in my prediction. Code runs.
// It says the last digit is 3 for every number which is wrong
// This is because we declared the var num = 103 globally, and it is affecting all the fucntion calls
// Because of the global declaration, every function call is going to use the global num
// This is bad because the code is now taking in diferent parameters but returning a value based on one global value.
// TO fix this we remove the global var num.
// Then we add num as a parameter in the function :getLastDigit(num)

// 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
2 changes: 2 additions & 0 deletions Sprint-3/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
return (weight / (height * height)).toFixed(1)
}
console.log(calculateBMI(70, 1.73))
7 changes: 7 additions & 0 deletions Sprint-3/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@
// 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(str) {
let snake_case = str.replaceAll(" ", "_");
return snake_case.toUpperCase()
}

console.log(UPPER_SNAKE_CASE("have you ever had a krispy kreme"))
13 changes: 13 additions & 0 deletions Sprint-3/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@
// 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(str) {
let penceStringWithoutTrailingP = str.substring(0, str.length - 1);

let paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
let pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);

let pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");

console.log(`£${pounds}.${pence}`);
}

toPounds("5045p")
20 changes: 10 additions & 10 deletions Sprint-3/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ function pad(num) {
}

function formatTimeDisplay(seconds) {
const remainingSeconds = seconds % 60;
const totalMinutes = (seconds - remainingSeconds) / 60;
const remainingMinutes = totalMinutes % 60;
const totalHours = (totalMinutes - remainingMinutes) / 60;
const remainingSeconds = seconds % 60; // 1
const totalMinutes = (seconds - remainingSeconds) / 60; // 1
const remainingMinutes = totalMinutes % 60; // 1
const totalHours = (totalMinutes - remainingMinutes) / 60; //0

return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}
Expand All @@ -21,18 +21,18 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// 3 times

// Call formatTimeDisplay with an input of 61, now answer the following:

console.log(formatTimeDisplay(61)) // 00:01:01
// b) What is the value assigned to num when pad is called for the first time?
// =============> write your answer here
// 0

// c) What is the return value of pad when it is called for the first time?
// =============> write your answer here
// "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
// 1

// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> write your answer here
// "01"
67 changes: 52 additions & 15 deletions Sprint-3/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,61 @@
// Make sure to do the prep before you do the coursework
// 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.

// original code:
// function formatAs12HourClock(time) {
// const hours = Number(time.slice(0, 2));
// if (hours > 12) {
// return `${hours - 12}:00 pm`;
// }
// return `${time} am`;
// }

// const currentOutput = formatAs12HourClock("08:00");
// const targetOutput = "08:00 am";
// console.assert(
// currentOutput === targetOutput,
// `current output: ${currentOutput}, target output: ${targetOutput}`
// );

// const currentOutput2 = formatAs12HourClock("23:00");
// const targetOutput2 = "11:00 pm";
// console.assert(
// currentOutput2 === targetOutput2,
// `current output: ${currentOutput2}, target output: ${targetOutput2}`
// );

// my code:
function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
if (hours >= 12) {
return `${hours - 12}:${time.slice(3)} pm`;
}
return `${time} am`;
return `${time}:${time.slice(3)} am`;
}

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);
const cases = [
{ input: "00:00", expected: "12:00 am" }, // midnight
{ input: "01:00", expected: "01:00 am" },
{ input: "02:00", expected: "02:00 am" }, // your failing test
{ input: "09:00", expected: "09:00 am" },
{ input: "11:59", expected: "11:59 am" },
{ input: "12:00", expected: "12:00 pm" }, // noon
{ input: "12:30", expected: "12:30 pm" },
{ input: "13:00", expected: "01:00 pm" },
{ input: "23:00", expected: "11:00 pm" }, // your other test
{ input: "23:59", expected: "11:59 pm" },
];

const currentOutput2 = formatAs12HourClock("23:00");
const targetOutput2 = "11:00 pm";
console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
function runTests(cases) {
let passed = 0;
for (const { input, expected } of cases) {
const actual = formatAs12HourClock(input);
const ok = actual === expected;
if (ok) passed++;
console.log(
`${ok ? "PASS" : "FAIL"} input: ${input} expected: ${expected} actual: ${actual}`
);
}
console.log(`\n${passed}/${cases.length} passed`);
}
runTests(cases);
Loading