Skip to content
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

class-jul2024-1 | Saidumar Akbarov | Module-JS1 | week1 #48

Open
wants to merge 3 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
4 changes: 2 additions & 2 deletions week-1/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?
4 changes: 3 additions & 1 deletion week-1/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;
var age = 33;
age = age + 1;

console.log(age);
2 changes: 1 addition & 1 deletion week-1/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
4 changes: 3 additions & 1 deletion week-1/errors/3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);

console.log(last4Digits);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
Expand Down
4 changes: 2 additions & 2 deletions week-1/errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const a12HourClockTime = "20:53";
const a24hourClockTime = "08:53";
2 changes: 1 addition & 1 deletion week-1/exercises/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let count = 0;

count = count + 1;
count = count + 1; // reassigned

// 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
7 changes: 6 additions & 1 deletion week-1/exercises/decimal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

const num = 56.5467;
const wholeNumberPart = Math.floor(num);
const decimalPart = parseFloat((num - wholeNumberPart).toFixed(4));
const roundedNum = Math.round(num);

console.log(wholeNumberPart);
console.log(decimalPart);
console.log(roundedNum);
// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

// Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num )
Expand Down
5 changes: 5 additions & 0 deletions week-1/exercises/initials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";
let initials = `${firstName.slice(0, 1)}${middleName.slice(
0,
1
)}${lastName.slice(0, 1)}`;

console.log(initials);
// Declare a variable called initials that stores the first character of each string in upper case to form the user's initials
// Log the variable in each case
7 changes: 7 additions & 0 deletions week-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ 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 = filePath.slice(0, lastSlashIndex);
console.log(`The dir part of ${filePath} is ${dir}`);

const lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex);
console.log(`The ext part of ${filePath} is ${ext}`);
1 change: 1 addition & 0 deletions week-1/exercises/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const minimum = 1;
const maximum = 100;

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
Expand Down
4 changes: 4 additions & 0 deletions week-1/interpret/percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,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
// - 4,5,10

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

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

// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// - turns the value of the variable to the number data type and returns its value with elimination the comma
5 changes: 5 additions & 0 deletions week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ 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?
// - 7

// b) How many function calls are there?
// - 1

// c) Using documentation on MDN, explain what the expression movieLength % 60 represents
// - divides value of it by 60 and returns the remainder

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// - it counts the integer that could be divided by 60 without reminder

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// - its represents the movie length in hours, minutes and seconds. A better name for this variable is movieDuration

// f) Think about whether this program will work for all values of movieLength.
// Think of what values may cause problems for the code.
Expand Down
12 changes: 8 additions & 4 deletions week-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ const penceString = "399p";
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
); // 399

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

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

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

Expand All @@ -27,3 +27,7 @@ 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): returns numeric part of value
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): adds "0" before given value for the length of 3 digits
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): returns the part of string between begin and 1 digit - "3"
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): gets the first digit of number and adds "00" at the end