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

NW6 | Fathi_Kahin | Module-JS1 | Week4 #176

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9b4014f
week1 two errors corrected
fhkahin Nov 7, 2023
db779dc
card number fixed
fhkahin Nov 7, 2023
734380d
clock time fixed
fhkahin Nov 7, 2023
0bd33c2
commented out
fhkahin Nov 7, 2023
c05e34c
count completed
fhkahin Nov 7, 2023
b5a6fbc
whole number assigned
fhkahin Nov 8, 2023
5ffdda3
decimals updated
fhkahin Nov 8, 2023
aa5e050
initials updated
fhkahin Nov 8, 2023
928fcce
path.js updated
fhkahin Nov 8, 2023
86cdee4
random .js updated
fhkahin Nov 8, 2023
197fc89
commented answers
fhkahin Nov 8, 2023
16abd13
objects updated
fhkahin Nov 8, 2023
116e462
commented
fhkahin Nov 8, 2023
a71b912
percentage-solved
fhkahin Nov 8, 2023
0c8964f
to-pounds js completed
fhkahin Nov 8, 2023
d872c9d
NW6 | FATHI_KAHIN | JS1 | week 2 exercises | WEEK2
fhkahin Nov 11, 2023
9426b07
capitalized str
fhkahin Nov 11, 2023
49bb69d
debur and aerrors udated
fhkahin Nov 14, 2023
e8f119b
1.js completed
fhkahin Nov 15, 2023
2fa1a6f
2.js completed
fhkahin Nov 15, 2023
04f42c4
2.js saved
fhkahin Nov 15, 2023
4fd105e
answered to-pounds.js
fhkahin Nov 15, 2023
8942482
vat.js answered
fhkahin Nov 15, 2023
3dc7cc7
2.js commented out
fhkahin Nov 15, 2023
718fde9
Time-Format answered
fhkahin Nov 15, 2023
f653451
time-format updated
fhkahin Nov 15, 2023
beb275f
title commentedout
fhkahin Nov 17, 2023
d975b55
format-as-12-hours.js completed!
fhkahin Nov 22, 2023
f5f8377
format-as-12-hours.js
fhkahin Nov 22, 2023
3dc1d86
get-angle-type.js updated
fhkahin Nov 22, 2023
1a4da93
get-card-value.js updated
fhkahin Nov 22, 2023
3f51bfb
get-card-value.js updated
fhkahin Nov 22, 2023
06822f6
get-card-value.js update
fhkahin Nov 22, 2023
9a62aee
node is-proper-fraction.js tested
fhkahin Nov 22, 2023
e158922
is-valid-triangle.js updated
fhkahin Nov 22, 2023
f6e2ad0
node format-as-12-hours.js updated
fhkahin Nov 22, 2023
7d9babf
is-vowel.js the exrta (i)removed
fhkahin Nov 22, 2023
a9d634a
is-vowel updated
fhkahin Nov 22, 2023
94ded21
count.test passed!
fhkahin Nov 29, 2023
30a051c
get ordinal pass!
fhkahin Nov 29, 2023
c8ef7b0
is prime pass
fhkahin Nov 29, 2023
54a45a1
password validator pass
fhkahin Nov 29, 2023
0f2020c
repeat.test Pass
fhkahin Nov 29, 2023
3dd3349
find.js answered
fhkahin Nov 30, 2023
a29d85f
updated
fhkahin Nov 30, 2023
97d8478
card validator file passed test!
fhkahin Nov 30, 2023
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
Binary file added .DS_Store
Binary file not shown.
Binary file added week-1/.DS_Store
Binary file not shown.
6 changes: 4 additions & 2 deletions week-1/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?

//answer. we comment the lines out like this
5 changes: 5 additions & 0 deletions week-1/errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

const age = 33;
age = age + 1;
// you cannot re-assign const instead we can use: let.

//let age = 33;
//age = age + 1;

5 changes: 5 additions & 0 deletions week-1/errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@

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

// we should declare cityOfBirth before console.logging

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

//the card number must have a string format if we want to use the slice method

const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
// Make and explain a prediction about why the code won't work
Expand Down
7 changes: 6 additions & 1 deletion week-1/errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";
// variables must start with letters

const twelveHourClockTime = "20:53";
const twentyFourhourClockTime = "08:53";

7 changes: 6 additions & 1 deletion week-1/exercises/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
let count = 0;

count = count + 1;
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

count = count + 1; //line three is increasing 0 by 1 and the = is the operator here.S



16 changes: 12 additions & 4 deletions week-1/exercises/decimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ const num = 56.5467;

// 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 )
// Create a variable called decimalPart and assign to it an expression that evaluates to 0.5467 ( the decimal part of num )
// Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number )
// Create a variable called wholeNumberPart and assign the whole number part of num to it
const wholeNumberPart = Math.floor(num);

// Create a variable called decimalPart and assign the decimal part of num to it
const decimalPart = num - wholeNumberPart;

// Create a variable called roundedNum and assign num rounded to the nearest whole number to it
const roundedNum = Math.round(num);

console.log("Whole Number Part:", wholeNumberPart);
console.log("Decimal Part:", decimalPart);
console.log("Rounded Number:", roundedNum);

// Log your variables to the console to check your answers
2 changes: 2 additions & 0 deletions week-1/exercises/initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ let lastName = "Johnson";

// 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

let initials = (firstName[0] + middleName[0] + lastName[0]).toUpperCase();
31 changes: 31 additions & 0 deletions week-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,34 @@ 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 filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";

// The index of the last slash
const lastSlashIndex = filePath.lastIndexOf("/");

// The "base" part from the filePath
const base = filePath.slice(lastSlashIndex + 1);

// Logging the "base" part
console.log(`The base part of ${filePath} is ${base}`);

//.............................................................

// Extracting the "dir" part from the filePath
const dir = filePath.slice(0, lastSlashIndex);

// The console-log
console.log(`The dir part of ${filePath} is ${dir}`);
//.............................................................

// Extracting the "ext" part from the "base" part
const extIndex = base.lastIndexOf(".");
const ext = extIndex !== -1 ? base.slice(extIndex + 1) : "No extension";

// the console log
console.log(`The ext part of ${filePath} is ${ext}`);
//......................................................


5 changes: 5 additions & 0 deletions week-1/exercises/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 several times to build an idea of what the program is doing

//Answer

// The variable -num- wil contain a random number between 1 and 100.

6 changes: 6 additions & 0 deletions week-1/explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ Let's try an example.
In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;


What effect does calling the `alert` function have?
// was unable to do this. it only worked when I used console.log.

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?
What is the return value of `prompt`?
..........................

// I was only able to use console.log
8 changes: 8 additions & 0 deletions week-1/explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ In this activity, we'll explore some additional concepts that you'll encounter i
Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?
`console.log`

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

Try also entering `typeof console`

Answer the following questions:

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

The console.log() method prints a message to the web console. 

The console.assert() method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

`.` means execute this”.
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
// ...........there are 2 function calls: 1) carPrice.replaceAll and 2) priceAfterOneYear.replaceAll

// b) Identify all the lines that are variable reassignment statements
//.......1) carPrice = Number(carPrice.replaceAll(",", "")); and 2) priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

// c) Identify all the lines that are variable declarations
//.....1. `let carPrice = "10,000";` 2. `let priceAfterOneYear = "8,543";` 3. `const priceDifference = carPrice - priceAfterOneYear;` 4. `const percentageChange = (priceDifference / carPrice) * 100;`

// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//..... it is replacing all the comas in the string so that we can have numbers that we can calculate.
12 changes: 7 additions & 5 deletions week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,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?
// a) How many variable declarations are there in this program? There are five variable declarations in this program:

// b) How many function calls are there?
// b) How many function calls are there? There are zero function calls

// c) Using documentation on MDN, explain what the expression movieLength % 60 represents
// c) Using documentation on MDN, explain what the expression movieLength % 60 represents. it represents the reminder.
// (It calculates the remaining seconds after all the full minutes have been counted.)

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? It extracts the seconds in the movie length.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// the variable result represent (hours:minutes:seconds) time format, a better name would be (formattedTime)

// f) Think about whether this program will work for all values of movieLength.
// Think of what values may cause problems for the code.
// Decide the result should be for those values, then test it out.
// Can you find any values of movieLength which don't give you what you'd expect?
// Can you find any values of movieLength which don't give you what you'd expect? yes, it is not considering (days) in the calculation.
15 changes: 15 additions & 0 deletions week-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,18 @@ 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);
// : This line creates a new string variable
// which represents the price in pence without the 'p' character.
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// : This line creates a new string variable with the value "399,"
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
// : This line takes the first character of the `paddedPenceNumberString`,
// which represents the pounds.
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
// : This line extracts the pence part of the `paddedPenceNumberString`
// 6. console.log(`£${pounds}.${pence}`);
// : This line combines the `pounds` and `pence` variables with the '£' symbol to to make it easy to read.



11 changes: 11 additions & 0 deletions week-2/debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ function multiply(a, b) {
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
localStorage

// the result is showing 320, which is not fully correct due to the term LocalStorage.
// it should be written as below:

function multiply(a, b) {
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

13 changes: 11 additions & 2 deletions week-2/debug/1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
// Predict and explain first...

function sum(a, b) {
return;
a + b;
return;
a + b }

//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// the semi colon in the return statement will stop the function execution. it should be as follows:

function sum(a, b) {
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);


21 changes: 16 additions & 5 deletions week-2/debug/2.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
// Predict and explain first...

const num = 103;
// const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
}
return num.toString().slice(-1); }

// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
//...........................................................................
// first the (num) is not defined, second the (const num = 103;) is a fixed number and that is what it will
// calculate for all numbers, their last digit will remain 3, we can fix this by using
// the following code:

function getLastDigit(num) {
return num.toString().slice(-1); }

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
22 changes: 20 additions & 2 deletions week-2/errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
// interpret the error message and figure out why it's happening, if your prediction was wrong

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}

//....................................
// the problem is that (str) is already the input to the function

function capitalise(str) {
let capitalizedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return capitalizedStr;
}

const originalString = "i love cyf";
const capitalizedString = capitalise(originalString);

console.log(`Original: ${originalString}`);
console.log(`Capitalized: ${capitalizedString}`);




33 changes: 32 additions & 1 deletion week-2/errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,36 @@ function convertToPercentage(decimalNumber) {

return percentage;
}
//.................................

// ANSWER.
// We want the computer to perform a task: take the (decimalNumber ),, multiply it by 100, and add a '%' sign.
// However, we made a mistake by telling the computer "Hey computer, our special number is 'decimalNumber,' and by the way, it's 0.5!"
// This will confuse the computer and will result an error. To fix this, we need to correct our instructions,
// making sure that we only tell the computer about the (decimalNumber ) just once. If we solve this mistake,
// the computer will be able to carried out the task, (this is really a good example of how important is to give clear instructions,
// and how important is to avoid repetition in computer programming).

//Playing computer results:

// const decimalNumber is declared in the local scope
// const decimalNumber = 0.5;
// A syntax error occurs here because you're trying to redeclare 'decimalNumber' in the same scope.

// const percentage = `${decimalNumber * 100}%`;
// This will not be reached due to the syntax error.

// then we Called the function
// convertToPercentage();
// This also results in a syntax error because we are trying to redeclare 'decimalNumber' in the same scope.

function convertToPercentage() {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}


console.log(convertToPercentage());

console.log(decimalNumber);
17 changes: 14 additions & 3 deletions week-2/errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@
// this function should square any number but instead we're going to get an error
// what is happening? How can we fix it?

function square(3) {
return num * num;
}
// function square(3) {
// return num * num;
// }

//...........................................

//ANSWER


function square(num) {
return num * num;
}

console.log(square(4));
console.log(square(7));

Loading