Skip to content

Sprint 1 coursework solutions #38

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

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 11 additions & 0 deletions Solouions/Sprint-1/count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let count = 0;

count = count + 1;

// Describe what line 3 is doing, in particular focus on what = is doing

// Line 3 is performing an assignment, giving a new value to the count variable declared on line 1.
// The new value is the result of the expression on the right side: count + 1.
// So this operation is incrementing the count variable by 1, so after this line, count will now have the value 1.

console.log(`The value of count is now: ${count}`);
15 changes: 15 additions & 0 deletions Solouions/Sprint-1/decimal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const num = 56.4567;

// Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56
const wholeNumberPart = Math.floor(num);

// Create a variable called decimalPart and assign to it an expression that evaluates to 0.4567
const decimalPart = num - wholeNumberPart;

// Create a variable called roundedNum and assign to it an expression that evaluates to 57
const roundedNum = Math.round(num);

// Log your variables to the console to check your answers
console.log(`Whole number part: ${wholeNumberPart}`);
console.log(`Decimal part: ${decimalPart}`);
console.log(`Rounded number: ${roundedNum}`);
8 changes: 8 additions & 0 deletions Solouions/Sprint-1/initials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";

// Declare a variable called initials that stores the first character of each string.
const initials = firstName[0] + middleName[0] + lastName[0];

console.log(`The initials are: ${initials}`);
24 changes: 24 additions & 0 deletions Solouions/Sprint-1/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// The diagram below shows the different names for parts of a file path on a Unix operating system

// ┌─────────────────────┬────────────┐
// │ dir │ base │
// ├──────┬ ├──────┬─────┤
// │ root │ │ name │ ext │
// " / home/user/dir / file .txt "
// └──────┴──────────────┴──────┴─────┘

// (All spaces in the "" line should be ignored. They are purely for formatting.)

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}`);

// Create a variable to store the dir part of the filePath variable
const dir = filePath.slice(0, lastSlashIndex);

// Create a variable to store the ext part of the variable
const ext = base.slice(base.lastIndexOf("."));

console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);
19 changes: 19 additions & 0 deletions Solouions/Sprint-1/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const minimum = 1;
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 and running the program several times to build an idea of what the program is doing

// Breaking down the expression:
// 1. Math.random() generates a random number between 0 and 1
// 2. We multiply it by (maximum - minimum + 1) to scale it to our range
// 3. Math.floor() rounds down to the nearest integer
// 4. We add minimum to shift the range to start from the minimum value

// So num is a random integer between minimum and maximum values.

console.log(`Num is a random number between ${minimum} and ${maximum}: ${num}`);