Skip to content
Open
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 is updating the value of the count variable by adding 1 to its current value. The = operator is an assignment operator that assigns the result of the expression on the right (count + 1) back to the variable on the left (count). So, it takes the current value of count, adds 1 to it, and then stores that new value back in count.
2 changes: 1 addition & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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 = ``;
let initials = firstName[0] + middleName[0] + lastName[0];

// 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 = filePath.slice(filePath.lastIndexOf(".") + 1);
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
10 changes: 10 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const minimum = 1;
const maximum = 100;

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
console.log(num);

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
num = getRandomInt(minimum, maximum);
console.log(num);
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

// In this exercise, you will need to work out what num represents?
Expand Down
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +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?
// 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?
2 changes: 2 additions & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

const age = 33;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is an error when executing this code.
you can check if there are multiple declarations of the same variable

age = age + 1;
let age = 33;
age = age + 1;
3 changes: 3 additions & 0 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const cardNumber = 4533787178994213;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also there is an error when executing this code.
Maybe check if you are declaring things twice and if you are allowed to change constant variable types

const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);
console.log(`The last 4 digits of the card number are ${last4Digits}`);


// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
Expand Down
13 changes: 12 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
const 12HourClockTime = "20:53";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The code is still failing,
The best approach is to execute it via Node. Let me know if you need help wiht that

const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";

// The 12HourClockTime variable should store the time in 12 hour clock format
// The 24HourClockTime variable should store the time in 24 hour clock format
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work
// 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 variable names to get the correct values stored in the variables

const 24HourClockTime = "20:53";
const 12HourClockTime = "08:53";
14 changes: 13 additions & 1 deletion Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ 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
// 1. Line 1: Number
// 2. Line 2: replaceAll
// 3. Line 1: Number
// 4. Line 2: replaceAll
// 5. Line 3: console.log

// 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 is coming from line 4 and line 5 where the replaceAll function is being called. The error is occurring because there is a syntax error in the code. The correct syntax for the replaceAll function should be replaceAll(",", "") instead of replaceAll("," ""). To fix this problem, we need to add a comma between the two arguments in the replaceAll function calls.
// c) Identify all the lines that are variable reassignment statements
// 1. Line 1: carPrice
// 2. Line 2: priceAfterOneYear

// d) Identify all the lines that are variable declarations
// 1. Line 1: let carPrice = "10,000";
// 2. Line 2: let priceAfterOneYear = "8,543";


// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// The expression Number(carPrice.replaceAll(",","")) is first calling the replaceAll function on the carPrice variable, which is a string. The replaceAll function is replacing all occurrences of the comma character (",") with an empty string (""). This effectively removes the commas from the string. After that, the Number function is called on the resulting string to convert it into a number data type. The purpose of this expression is to convert the carPrice string, which contains commas, into a numerical value that can be used for calculations.

13 changes: 13 additions & 0 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,27 @@ 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?
// 1. Line 1: movieLength
// 2. Line 3: remainingSeconds
// 3. Line 4: totalMinutes
// 4. Line 6: remainingMinutes
// 5. Line 7: totalHours
// 6. Line 9: result

// b) How many function calls are there?
// 1. Line 9: console.log

// 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 is using the modulus operator (%) to calculate the remainder when movieLength is divided by 60. In this context, it is used to determine how many seconds are left after accounting for the full minutes in the movie length. Since there are 60 seconds in a minute, this expression gives us the number of seconds that do not make up a full minute in the total movie length.
// / For example, if movieLength is 8784 seconds, then 8784 % 60 would give us the remaining seconds after dividing 8784 by 60, which is 24 seconds.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The expression assigned to totalMinutes is calculating the total number of minutes in the movie length. It does this by first subtracting the remaining seconds (which are not part of a full minute) from the total movie length in seconds, and then dividing the result by 60 (the number of seconds in a minute). This gives us the total number of full minutes in the movie length. For example, if movieLength is 8784 seconds and remainingSeconds is 24 seconds, then totalMinutes would be calculated as (8784 - 24) / 60, which equals 146 minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// The variable result represents the formatted string that shows the movie length in hours, minutes, and seconds. A better name for this variable could be formattedMovieLength or movieDurationFormatted, as it more clearly indicates that it contains a formatted representation of the movie length.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// This code will work for all non-negative integer values of movieLength, as it is designed to calculate the hours, minutes, and seconds based on the total number of seconds. However, if movieLength is a negative value, the calculations may not make sense in the context of a movie length, and the output may not be meaningful. Additionally, if movieLength is not an integer (e.g., a floating-point number), the calculations may still work but could lead to unexpected results due to the way the modulus operator and division handle non-integer values. Therefore, it is best to ensure that movieLength is a non-negative integer for this code to function as intended.

5 changes: 5 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): creates a new string variable that contains the original string without the last character (the "p"), resulting in "399"
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, resulting in "399"
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the substring representing the pounds by taking all characters except the last two, resulting in "3"
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the substring representing the pence by taking the last two characters and pads it with trailing zeros if necessary, resulting in "99"
// 6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence, resulting in "£3.99"
3 changes: 3 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
// a small box pops up on the screen displaying your message and an OK button.

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?
// it displays a dialog box with your message, a text input field, and two buttons: OK and Cancel.
What is the return value of `prompt`?
// the value depends on your action. 1. Click OK with text: returns the entered text as a string. 2. Click OK with no text: Returns an empty string (""). 3. Click cancel or press esc: returns null.
3 changes: 3 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ Try also entering `typeof console`
Answer the following questions:

What does `console` store?
// it stores a Global Object provided by the browser environment. This object acts as a toolbox containing various utilities for logging information, timing code, and debugging.
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
// This is Dot Notation. It tells the computer to look inside the console object to find a specific function (method) named log or assert.
//The dot is the Member Access Operator. It is used to access the properties or methods belonging to an object.
4 changes: 2 additions & 2 deletions Sprint-1/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This README will guide you through the different sections for this week.

## 1 Exercises

In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation.
In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation.

https://developer.mozilla.org/en-US/docs/Web/JavaScript

Expand All @@ -28,7 +28,7 @@ You must use documentation to make sense of anything unfamiliar - learning how t

You can also use `console.log` to check the value of different variables in the code.

https://developer.mozilla.org/en-US/docs/Web/JavaScript
https://developer.mozilla.org/en-US/docs/Web/JavaScript

## 4 Explore - Stretch 💪

Expand Down
Loading