Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let count = 0;

//the = is reassigning the new value to the variable count of count
count = count + 1;

// Line 1 is a variable declaration, creating the count variable with an initial value of 0
Expand Down
6 changes: 4 additions & 2 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ 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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(
0
)}`;
console.log(initials);

// https://www.google.com/search?q=get+first+character+of+string+mdn

11 changes: 8 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// └──────┴──────────────┴──────┴─────┘

// (All spaces in the "" line should be ignored. They are purely for formatting.)
const path = require("node:path");

const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
Expand All @@ -17,7 +18,11 @@ 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 = path.dirname(filePath);
const ext = path.extname(filePath);

// https://www.google.com/search?q=slice+mdn
console.log(lastSlashIndex);
console.log(dir);
console.log(ext);

// https://www.google.com/search?q=slice+mdn
3 changes: 3 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const minimum = 1;
const maximum = 100;
/*First, the num variable generates a random number, which is then multiplied by the maximum value.
The result is rounded down using Math.floor to obtain a whole number, and finally, the minimum value is added.*/

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

console.log(num);
// In this exercise, you will need to work out what num represents?
// 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
Expand Down
5 changes: 3 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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 solve the problem you just comment out the lines.
3 changes: 2 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// trying to create an age variable and then reassign the value by 1

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

console.log(`I was born in ${cityOfBirth}`);
//you cannot console log a variable that hasn't been assigned yet because the program runs from the top to bottom.
const cityOfBirth = "Bolton";
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);
//the code did not work because the .slice can only be used on a string and not a number
console.log(last4Digits);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
Expand Down
7 changes: 5 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const _12HourClockTime = "20:53";
const _24hourClockTime = "08:53";

console.log(_12HourClockTime);
//a variable cannot start with a number
6 changes: 6 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ 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 is 1 function call.

// 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?
/*line 5 has a error. The error is occuring because there us a missing comma after the the first double quotations.
You can fix the error by just adding the comma.*/

// c) Identify all the lines that are variable reassignment statements
//line 4 and 5

// d) Identify all the lines that are variable declarations
//line 1,2,7 and 8.

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//the expression is removing the ,.
7 changes: 7 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,21 @@ 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 variable declarations in the program.

// b) How many function calls are there?
//there is 1 function call.

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
//the declaration represents the remainder when we devide the movie legth by 60

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//line 4 is subtracting the remainingMinutes from totalMinutes then dividing that by 60 to get the the total hours.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
/*the variable result is returning time format that shows the remaining hours, minutes and seconds left in the movie.
Better name for the variable could be remainingTime.*/

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//the code works for all values of movie length.
22 changes: 22 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,25 @@ console.log(`£${pounds}.${pence}`);

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

// 2. the const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1,
/*the substring(0) retuns 399p because substring (0) is the same as copying the entire string as it has no
end parameter it will extract from start to end and
the length -1 with remove the last character meaning this whole code will return 399.*/

// 3. the const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0")
/* pedStart(3, "0") represent the number of characters a string should have in this case 3, and if the string dont meet the number of characters
the start of the string will be filled with "0". But in this case the string length is already 3, therefor there
the padStart will not change anything*/

// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2
/* What this code is doing is first calling the operator substring, but since the method has no end parameter
it will extract the whole string, after that the length -2 operator is called which removes the last 2 characters of the string so
that the whole code returns "3" */

// 5. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0")
/* What this code is doing is firstly it will extract the last 2 characters of the string and
padEnd makes sure that the string has atleast 2 charaters which it does. Therefore this will return "99" */

// 6. console.log(`£${pounds}.${pence}`)
// this retuns 3.99
7 changes: 7 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?

- There was a pop up at the top of the screen that says "Hello world"

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?

- There was a pop up that prompted me to enter my name.

What is the return value of `prompt`?

- it displays a dialog that prompts user to enter a value.
12 changes: 12 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?

- this was the output "ƒ log() { [native code] }"

Now enter just `console` in the Console, what output do you get back?

- this was the output "console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}"

Try also entering `typeof console`

- It returned "object"

Answer the following questions:

What does `console` store?

- It stores debugging methods like, log, error, assert.

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?

- console.log means outputting information to the console.
-console.assert means to perform a conditional check in JavaScript, where it logs an error message to the console only if a specified condition are false.
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