Skip to content

Commit

Permalink
wk 1 feedback considered and changed accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 20, 2024
1 parent a324dc9 commit 4caf351
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
6 changes: 4 additions & 2 deletions week-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +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

let dirPath=filePath.slice(0,-8);
let dirPath = filePath.slice(0, lastSlashIndex);
console.log(dirPath);
console.log(base);
let extPath = base.includes(".") ? base.slice(base.lastIndexOf(".") + 1) : "";
console.log(extPath);

10 changes: 5 additions & 5 deletions week-1/exercises/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const maximum = 100;

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

// 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
// Try logging the value of num several times to build an idea of what the program is doing - math,random gives a value between 0 and 1, however 0 and 1 are not included. max - min +1 is 100 so a random number multiplied by 100 is anywhere between 0 and 100 but 0 and 100 not included. then add +1 and then 100 is included. math. floor rounds the number. so this function is giving us a random number between 0 and 100
// math.random gives a value between 0 (inclusive) and 1 (exclusive).
// max - min + 1 is 100, so a random number multiplied by 100 is between 0 (inclusive) and 100 (exclusive).
// Adding +1 shifts the range to be between 1 and 101 (exclusive).
// Math.floor rounds the number, so this function gives us a random whole number between 1 and 100 (inclusive).

console.log(num);
console.log(num);
9 changes: 6 additions & 3 deletions week-1/interpret/percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ 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 - line 4,5,8,10
// a) How many function calls are there in this file?
//Write down all the lines where a function call is made - line 4,5,8,10

// b) Identify all the lines that are variable reassignment statements - line 4,5,

// c) Identify all the lines that are variable declarations - line 1,2
// c) Identify all the lines that are variable declarations - line 1,2, 7, 8

// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? - it is replacing all commas, so commas are being deleted
// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing -
//what is the purpose of this expression? - it is replacing all commas, so commas are being deleted
//the number() chnages string to a number
2 changes: 1 addition & 1 deletion week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ console.log(result);

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

// b) How many function calls are there? - 2
// b) How many function calls are there? - there's only 1 which is console.log

// c) Using documentation on MDN, explain what the expression movieLength % 60 represents - The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.

Expand Down
8 changes: 4 additions & 4 deletions week-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const penceString = "399p"; //this defines the value of the pence in a string
const penceString = "399p"; //this defines the value of the pence in a string which is 399p

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
); // substring means it extracts a character, it is usually written like this substring(indexStart) or substring(indexStart,indexEnd)
// in this example it is substring (0, penceString.lenght -1) which means 0 is the first character which is 3 in this example and -1 means the last character is being cut off so it will be 399

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // this means it will add a character or value to the string until it reaches the length required
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // this means it will add a character or value to the string until it reaches the length required which gives a value of 399 as it already is 3 lenghts long
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
Expand All @@ -15,9 +15,9 @@ const pounds = paddedPenceNumberString.substring(
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0"); // substring in this example means it will cut off the first 2 characters fromt he start so it will be 3
// padend means it will add the specified character starting from the end until it reaches the desired number
// padend means it will add the specified character starting from the end until it reaches the desired number which gives a value of 99

console.log(${pounds}.${pence}`); // this will log the string value of pound and pence
console.log(${pounds}.${pence}`); // this will log the string value of pound and pence which is £.99

// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds
Expand Down

0 comments on commit 4caf351

Please sign in to comment.