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

Feature/week 1 exercises #199

Open
wants to merge 4 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
3 changes: 1 addition & 2 deletions week-1/errors/0.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion 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;
let age = 33;
age = age + 1;
console.log(age);
4 changes: 2 additions & 2 deletions 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: 2 additions & 2 deletions week-1/errors/3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
// Make and explain a prediction about why the code won't work
Expand Down
5 changes: 3 additions & 2 deletions week-1/errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const twelveHourClockTime = "20:53";
const twenty_four_hourClockTime = "08:53";
console.log(twenty_four_hourClockTime + ', ' + twelveHourClockTime);
3 changes: 1 addition & 2 deletions week-1/exercises/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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
6 changes: 6 additions & 0 deletions week-1/exercises/decimal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

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

console.log("Whole Number Part:", wholeNumberPart);
console.log("Decimal Part:", decimalPart);
console.log("Rounded Number:", 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
3 changes: 2 additions & 1 deletion week-1/exercises/initials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";

let initials = firstName.charAt(0).toUpperCase()+middleName.charAt(0).toUpperCase()+lastName.charAt(0).toUpperCase();
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
9 changes: 6 additions & 3 deletions week-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);
const dir = filePath.slice(0, lastSlashIndex);
const lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex + 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to give you an alternative. Could be:
filePath.split('.')[1]


// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable
console.log(`The base part of ${filePath} is ${base}`);
console.log(`The directory part of ${filePath} is ${dir}`);
console.log(`The extension part of ${filePath} is ${ext}`);
5 changes: 4 additions & 1 deletion week-1/exercises/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ 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
// 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 random decimal number
// and 100-1+1 = 100;
// when decimal value multiply with 100 it and math.floor gives a whole no then every this results shows in a different
7 changes: 5 additions & 2 deletions week-1/explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ Let's try an example.

In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

A dialog box with message display on top of the page
What effect does calling the `alert` function have?
A dialog box with ok button displays with message when user click on ok button the dialog box disappears

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`.

its works properly I use console.log(nyName); it displays my name that is entered on prompt dialog box
What effect does calling the `prompt` function have?
A dialog box is opened on the top of the page with a textbox and to buttons ok and cancel
What is the return value of `prompt`?
if user click on ok prompt return a string and if user click on cancel it returns null
85 changes: 82 additions & 3 deletions week-1/explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,91 @@ 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?

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

console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
assert
:
ƒ assert()
clear
:
ƒ clear()
context
:
ƒ context()
count
:
ƒ count()
countReset
:
ƒ countReset()
createTask
:
ƒ createTask()
debug
:
ƒ debug()
dir
:
ƒ dir()
dirxml
:
ƒ dirxml()
error
:
ƒ error()
group
:
ƒ group()
groupCollapsed
:
ƒ groupCollapsed()
groupEnd
:
ƒ groupEnd()
info
:
ƒ info()
log
:
ƒ log()
memory
:
MemoryInfo {totalJSHeapSize: 10000000, usedJSHeapSize: 10000000, jsHeapSizeLimit: 2190000000}
profile
:
ƒ profile()
profileEnd
:
ƒ profileEnd()
table
:
ƒ table()
time
:
ƒ time()
timeEnd
:
ƒ timeEnd()
timeLog
:
ƒ timeLog()
timeStamp
:
ƒ timeStamp()
trace
:
ƒ trace()
warn
:
ƒ warn()
Try also entering `typeof console`

'object'
Answer the following questions:

What does `console` store?
It can not store the information it only display the information
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
console is an object and log and assert are both functions '.' is used to access the functions like
console.log("hello world"); it display the message inside log on console
console.assert(condition,'message'); if condition is false then it display the message
13 changes: 13 additions & 0 deletions week-1/interpret/percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ 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 three function calls
// 1) carPrice.replaceAll();
// 2) priceAfterOneYear.replaceAll()
// 3) console.log()

// b) Identify all the lines that are variable reassignment statements
// There are two lines of Variable reassignment
// 1) carPrice = Number(carPrice.replaceAll(",", "")); After removing commas
// 2) priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); After removing commas

// c) Identify all the lines that are variable declarations
// There are four lines of variable declaration
// 1) let carPrice
// 2) let priceAfterOneYear
// 3) const priceDifference
// 4) const percentageChange

// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// It removes commas to the price and also convert the string into Numbers
20 changes: 19 additions & 1 deletion week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = 86400; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -14,16 +14,34 @@ 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?
// 1) const movieLength
// 2) const remainingSeconds
// 3) const remainingMinutes
// 4) const totalHours
// 5) const remainingHours
// 6) const result

// b) How many function calls are there?
// console.log(result);

// c) Using documentation on MDN, explain what the expression movieLength % 60 represents
// The operator % is modulus operator that gives reminder result It divide the movieLength value with 60

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// const totalMinutes = (movieLength - remainingSeconds) / 60;
// movieLength - remainingSeconds: Removes the extra seconds that aren't part of a full minute from the total seconds.
// Converts the remaining time (in seconds) into minutes by dividing the total seconds by 60.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// I think movieTotalTime is better because this program is about movie time so its better to assign variable name clearly

// f) Think about whether this program will work for all values of movieLength.
// yes this code is work for all values in second only 24hours formate shows true result

// Think of what values may cause problems for the code.
// I enter 86400 value that is not work properly

// Decide the result should be for those values, then test it out.
// the result is 0:0:0 on entering 86400
// Can you find any values of movieLength which don't give you what you'd expect?
// yes the value that is greater then or equal to 86400 then code did not work properly
16 changes: 4 additions & 12 deletions week-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const penceString = "399p";

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);

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

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

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

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

Expand Down