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|Bakhat Begum|Module-JS1 |Bakha/week-3| Sprint-3|Week-3 #162

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6813bfc
added command and variables
Nov 6, 2023
49d40f7
added variable, working with Math.floor, Math.roound,Math.random and …
Nov 8, 2023
c85d42b
working on file
Nov 9, 2023
dda5f90
working on a file path
Nov 9, 2023
0c65f52
for update
BakhatBegum Nov 11, 2023
ba7225d
working on BMI
BakhatBegum Nov 13, 2023
88cc3c6
working with toUppercase and white space
BakhatBegum Nov 13, 2023
7af8cc5
Prediction and explanation with output results
BakhatBegum Nov 15, 2023
e4f4ad5
have worked on argument and function parameter.
BakhatBegum Nov 15, 2023
fdee53e
I have worked on function, variable, Math.floor, Math.round and toFixed
BakhatBegum Nov 18, 2023
f52f53f
calling funtion
BakhatBegum Nov 18, 2023
ae50334
update code
BakhatBegum Nov 19, 2023
addc187
next solution
BakhatBegum Nov 19, 2023
2591330
multiplying price
BakhatBegum Nov 19, 2023
0e678b1
working on assertion
BakhatBegum Nov 20, 2023
5e757d5
working on angle
BakhatBegum Nov 20, 2023
646bb10
added condition
BakhatBegum Nov 20, 2023
c985e13
working on fraction
BakhatBegum Nov 22, 2023
569154a
function to return triangle
BakhatBegum Nov 22, 2023
9b7c15a
fraction output
BakhatBegum Nov 22, 2023
5d5b75a
condition for fraction
BakhatBegum Nov 22, 2023
3e5f474
store expression in new variable.
BakhatBegum Nov 22, 2023
df15012
working on Unicode character
BakhatBegum Nov 22, 2023
ba3a263
understanding code and try to figure out my error.
BakhatBegum Nov 22, 2023
4b5f604
changed return value
BakhatBegum Nov 23, 2023
569c6fd
debug errors
BakhatBegum Nov 23, 2023
71954f9
some codes were deleted my mistakes
BakhatBegum Nov 26, 2023
f115c6f
added some lines of code
BakhatBegum Nov 26, 2023
984afdf
Because of software I lost my codes and rewrite code again.
BakhatBegum Nov 26, 2023
9814ace
added variable
BakhatBegum Nov 26, 2023
a713454
added test.json file.
BakhatBegum Nov 27, 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
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 ?
5 changes: 3 additions & 2 deletions week-1/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;
age = age + 1;
let age = 33;
age += 1;
console.log(age);
3 changes: 2 additions & 1 deletion week-1/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
//ans : In JavaScrip/node.js the code executed from top to bottom, any variable must be declare before log it to console.

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

console.log(last4Digits);
// 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
//ans: I think we use .slice method for string. According to me, .toFixed() method will work on card. The method .toFixed() is used for numerical values .
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
7 changes: 5 additions & 2 deletions week-1/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 twelveHourClockTime = "20:53";
const twentyOneHourClockTime = "08:53";
console.log(twelveHourClockTime);
console.log(twentyOneHourClockTime);
// we can not initialize variable with numbers or with first capital letter. JavaScript is a case sensitive language.
4 changes: 4 additions & 0 deletions week-1/exercises/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ let count = 0;

count = count + 1;

console.log(count);

// 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
//ans: line three is a statement which give instruction the computer to execute code.

7 changes: 7 additions & 0 deletions week-1/exercises/decimal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

const num = 56.5467;
const wholeNumberPart = Math.trunc(num);
console.log(wholeNumberPart );

const decimalPart = (num - Math.floor(num)).toFixed(4); // if we console.log the decimalPart = Math.floor(num); output : 56, we subtract original number with result.
console.log(decimalPart);

const roundedNum = Math.round(num);
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
15 changes: 12 additions & 3 deletions week-1/exercises/initials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";
let firstName = "creole";
let middleName = "katherine";
let lastName = "johnson";

let initials = firstName.charAt(0).toUpperCase() + firstName.slice(1);
let initialsTwo = middleName.charAt(0).toUpperCase() + middleName.slice(1);
let initialsThree = lastName.charAt(0).toUpperCase() + lastName.slice(1);


console.log(initials);
console.log(initialsTwo);
console.log(initialsThree);

// 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
14 changes: 13 additions & 1 deletion week-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@

const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
const base = filePath.slice(lastSlashIndex + 1)
console.log(`The base part of ${filePath} is ${base}`);

// Create a variable to store the dir part of the filePath variable

const directory = filePath.slice(0, lastSlashIndex);
console.log(`The base part of ${filePath} is ${directory}`);


// Create a variable to store the ext part of the variable

const extPath = base.lastIndexOf(".");
const ext = extPath !== -1? base.slice(extPath + 1): "No extension";
console.log(`The base part of ${filePath} is ${ext}`);



6 changes: 6 additions & 0 deletions week-1/exercises/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ 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

console.log(num);

//ans : we declared variable minimum with vale 1, and maximum with 100. We have an other variable num with statement.
//We use Meth.floor method to erase decimal point and Math.random method to take any number include 0 and exclusive 101.

9 changes: 9 additions & 0 deletions week-1/explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?

ans: I used function greeting(){
alert("Hello World!")
};
greeting();

To invoke mean to call or execute. So when i invoke function 'greeting', a message pops up on screen. It mean alert will appeared the message in screen.

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?
ans: It well pop up box of information for user to input some text.
What is the return value of `prompt`?
ans: What is your name? With textbox that user put there name..
9 changes: 9 additions & 0 deletions week-1/explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ 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?
ans: undefine, which may be mean as it does not have value or variable.

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

ans: The output that I get is debug and error.

Try also entering `typeof console`

ans: the out that i get is object.

Answer the following questions:

What does `console` store?
ans; it might be store data.
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
ans; console.log will record something that happens in our program and print out it in text based in a terminal.
the console.assert writes an error message to console if the assertion is false. If the assertion is true nothing happens.
`.` means brackets.
8 changes: 8 additions & 0 deletions week-1/interpret/percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ console.log(`The percentage change is ${percentageChange}`);

// a) How many function calls are there in this file? Write down all the lines where a function call is made

//ans; 3 functions, line 4 , 5 and 10.

// b) Identify all the lines that are variable reassignment statements

//ans; there are 2 line 4, 5. ` carPrice `, `priceAfterOneYear `.

// c) Identify all the lines that are variable declarations

//ans; line 1, 2, 7, 8

// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?

// ans; It will replace the value of carPrice. Which means it will bring the number without comma.
19 changes: 17 additions & 2 deletions week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@ console.log(result);

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

//ans; Their is no variable declarations.

// b) How many function calls are there?

//ans; 1 function, console.log

// c) Using documentation on MDN, explain what the expression movieLength % 60 represents

//ans; the remainder of the division of movieLength by 60

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

//ans; the total remainingSeconds is in integer.
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// f) Think about whether this program will work for all values of movieLength.
// Think of what values may cause problems for the code.
//ans; the length of move in hours minutes and seconds. can be length.

//ans; it will bring an output result of 2 : 26: 24

// f) Think about whether this program will work for all values of movieLength.
//ans ; yes
// Think of what values may cause problems for the code.
// ans; infinity
// Decide the result should be for those values, then test it out.
// ans; the results undefine
// Can you find any values of movieLength which don't give you what you'd expect?
//ans; no
10 changes: 9 additions & 1 deletion week-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");



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

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

// You need to do a step-by-step breakdown of each line in this program
// Try and describe the purpose / rationale behind each step

// You should use MDN to look up substring, padStart and padEnd to interpret this program

// To begin, we can start with

// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 1. const penceString = "399p": initializes a string variable with the value "399p"
//ans:
// 3-6: extract a substring of the string '399p' that starts from index 0 and has a length of 'penceString.length - 1' (3) which gives '399'
// 8. if previous answer has length less than 3, add string '0' to reach given length of 3 - not applicable here.
// 9-12: for previous answer (399), start from index 0, string must of length 'paddedPenceNumberString.length - 2' = 1. Ans = 3
//14-16: here index starts from 1 '.substring(paddedPenceNumberString.length - 2)' and continue to last index from 'a.padEnd(2, "0");'. so starting from index 1 and going to las index gives 99
15 changes: 15 additions & 0 deletions week-2/debug/0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// Predict and explain first...
//Ans: The code defines a function called multiply that takes two parameters a and b.

//Inside the function, it simply prints out the result of multiplying a and b using console.log(a * b).

// After defining the function, the code calls the multiply function, passing 10 and 32 as the arguments.

// The results of the function call are inserted into a template literal `The result of multiplying 10 and 32 is ${multiply(10, 32)}`

// So when this line runs, it will call the multiply function, multiplying 10 and 32.

// The multiply function will print out 320.

// Then that 320 result gets inserted into the template literal, which prints out the full string:

// "The result of multiplying 10 and 32 is 320"

function multiply(a, b) {
console.log(a * b);
Expand Down
27 changes: 26 additions & 1 deletion week-2/debug/1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
// Predict and explain first...
//Ans: The code defines a function called sum that takes two parameters a and b.

//Inside the function, it simply prints out the result of adding a and b using return a * b.

// After defining the function, the code calls the sum function, passing 10 and 32 as the arguments.

// The results of the function call are inserted into a template literal `The result of adding 10 and 32 is ${multiply(10, 32)}`

// So when this line runs, it will call the sum function, adding 10 and 32.

// The sum function will not print out 42. So when you call sum(10, 32), the function executes return; which

// exits the function immediately without returning any value.

// Hence, since the function doesn't return anything explicitly, the returned value is undefined.

// Here is a correct code.
//function sum(a, b) {
// return a + b;
// }

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


// Here is a correct code.
function sum(a, b) {
return a + b;
}
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
25 changes: 20 additions & 5 deletions week-2/debug/2.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
// Predict and explain first...
// Ans: the code define num variable with value 0f 103. We have function called getLastDigit.
//Inside the function, it simply prints out the result of last digit using return num.toString().slice(-1).
//After defining the function, the code calls the getLastDigit() function, passing 42, 105 and 806 as the arguments.
//The results of the function call are inserted into a template literal
//`The last digit of 42 is ${getLastDigit(42)}`); output: 3
//`The last digit of 105 is ${getLastDigit(105)}`); output: 3
//`The last digit of 806 is ${getLastDigit(806)}`); output: 3

const num = 103;

function getLastDigit() {
const numOne = 42;
const numTwo = 105;
const numThree = 806;

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)}`);
console.log(`The last digit of 42 is ${getLastDigit(numOne, 42)}`);
console.log(`The last digit of 105 is ${getLastDigit(numTwo, 105)}`);
console.log(`The last digit of 806 is ${getLastDigit(numThree, 806)}`);

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
//Ans: The key issue is that getLastDigit() function doesn't accept any parameters. It always just returns the last digit of the num variable defined outside the function.
// So when you call getLastDigit(42), the 42 is ignored.
// Inside getLastDigit(), it converts the num variable (which is 103) to a string, takes the last character (3) and returns that.
// It has no way to access the 42 value passed to it.
// To fix it, you need to update the function to accept a parameter.
24 changes: 21 additions & 3 deletions week-2/errors/0.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
// Predict and explain first...
//Ans: You're absolutely right! Calling the capitalize function as shown would result in a SyntaxError.
//The key reason is that the capitalize function has not been defined anywhere before calling it.
//In JavaScript, you have to first declare/define a function before you can call it.

// write down the error you predict will be raised
// then call the function capitalise with a string input
//ans ; syntaxError.
// then call the function capitalize with a string input
// interpret the error message and figure out why it's happening, if your prediction was wrong
//ans; My prediction was right about syntaxError..

function capitalize(text) {
let str = `${text[0].toUpperCase()}${text.slice(1)}`;
return str;
}
let text = "i like ice-cream";
console.log(capitalize(text));



function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
//here is the correct
function capitalize(text) {
let str = `${text[0].toUpperCase()}${text.slice(1)}`;
return str;
}
let text1 = "i like ice-cream";
console.log(capitalize(text));
11 changes: 9 additions & 2 deletions week-2/errors/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Predict and explain first...

//ans ; we declared const decimalNumber inside the body function it mean it is Local scope, which never allow variable to call out side the function.
// as a result we face syntexError.
// Write down the error you predict will be raised
//ans; syntaxError
// Why will an error occur when this program runs?
//ans: Variable Scope: If the variable is defined within the function using the var, let, or const keyword, it is only accessible within that function's scope.
// Play computer with the example to work out what is going on

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

return percentage;
}
console.log(convertToPercentage(0.5));

console.log(decimalNumber);
// here is the second solution
// const decimalNumber = 0.5;
// console.log(convertToPercentage(decimalNumber));
Loading