Skip to content

Sheffield | May-2025 | Mayowa Fadare | Structuring and Testing Data Sprint-1 #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ 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
// line 3 increases the variable by adding +1 to the initial
11 changes: 8 additions & 3 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
let firstName = "Creola";
let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";
let lastName = "Johnson";

// Grab the first character of each name dynamically
const initials = firstName[0] + middleName[0] + lastName[0];

console.log(initials); // CKJ
// 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

7 changes: 4 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ 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(lastDotIndex);
console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);
// https://www.google.com/search?q=slice+mdn
5 changes: 5 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// 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
// Math.random() returns a random number in the interval (0,1 )
// Math.random() * (maximum - minimum + 1) this means the random decimal number will be multiplied by the range difference between maximum and minimum plus 1
// For minimum = 1 and maximum = 100, the range size is 100 - 1 + 1 = 100,
// Math.floor() rounds down to the nearest whole number
// + minimum shifts the entire range up, by the minimum value 1 and not 0
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -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?
//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?
// To prevent computer running two lines consecutively, we use double slash (//) at the beginning of each line.

4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
age = age + 1;
// age = age + 1;
// let age = 33;
// const.log(age);
3 changes: 3 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
// what's the error ?

console.log(`I was born in ${cityOfBirth}`);
// const cityOfBirth = "Bolton";

const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
6 changes: 6 additions & 0 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ 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
// const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits);
//.slice() is a method for strings and arrays, not numbers, and a cardNumber consist of number.
// after running the code, it gave TypeError: cardNumber.slice is not a function
// This was not what i predicted, and it gave the error due to javascript not recognising the command cardNumber.slice(-4);
// had to use the recognised command cardNumber.toString().slice(-4); for it to be recognised.
10 changes: 9 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";


const hour12ClockTime = "20:53 PM";
const hour24ClockTime = "08:53";
console.log(hour12ClockTime);
console.log(hour24ClockTime);
it gave a SyntaxError: Identifier directly after number, which mean a variable starting with a number, which is not allowed in js.

11 changes: 6 additions & 5 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,11 +12,12 @@ console.log(`The percentage change is ${percentageChange}`);
// Read the code and then answer the questions below

// a) How many function calls are there in this file? Write down all the lines where a function call is made

// There are 5 function calls on this file: in line 1, 4, 5 and 10.
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?

// The error comes from line 5, SyntaxError: Unexpected token, expected "," (5:60), can be corrected by adding coma (",","")
// c) Identify all the lines that are variable reassignment statements

// Line number 4 and 5
// d) Identify all the lines that are variable declarations

// Line number 1,2,7 and 8
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// To remove the commas in the string price and convert it to a numerical value (e.g., "10,000" to 10000)..
11 changes: 6 additions & 5 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ console.log(result);
// For the piece of code above, read the code and then answer the following questions

// a) How many variable declarations are there in this program?

// There are 6 variables
// b) How many function calls are there?

// There is 1 function
// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// The expression movieLength % 60 calculates the remainder when movieLength (in seconds) is divided by 60.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// line 4 means total and exact amount of movie length after removing the remaining seconds not used for movie
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// it represent the total time used for the movie in Hours, minutes and seconds. a better name could be movieduration
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// yes it will work, provided there are no negative integer
11 changes: 10 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const pounds = paddedPenceNumberString.substring(

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


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

Expand All @@ -25,3 +25,12 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"

// const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); removes the trailing p from the penceString, so the value will be "399".

// const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); pads the numeric string with zeros until it 3 digits character Long. value will be "399" and also ensuring consistency of 3 digits value.

// const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); extracts the pounds part from the padded string by taking all but the last two digits.Here, it will be "3".

// const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); extracts the last two characters as the pence portion and ensures it is always two digits.
// console.log(`£${pounds}.${pence}`); formats and prints the final price in pounds and pence format, hence it will output "£3.99"
Loading