Skip to content

Commit

Permalink
made changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayali436 committed Oct 21, 2023
2 parents 59c2a49 + 03fce56 commit fbfe16a
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 60 deletions.
5 changes: 3 additions & 2 deletions week-1/exercises/decimal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const num = 58.4567;

const num = 56.5467;

const wholeNumberPart = Math.round(num) - 2;
const decimalPart = num - Math.round(num);
Expand All @@ -11,7 +12,7 @@ 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 )
// Create a variable called decimalPart and assign to it an expression that evaluates to 0.4567 ( the decimal 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 )

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

<<<<<<< HEAD
const initials = `${firstName.substring(0, 1)}${middleName.substring(
0,
1
)}${lastName.substring(0, 1)}`;
console.log(initials);

// Declare a variable called initials that stores the first 3 characters of each string in upper case
=======
// Declare a variable called initials that stores the first character of each string in upper case to form the user's initials
>>>>>>> 03fce56db903fb986ff36f73e4d57cebfa18707c
// Log the variable in each case
2 changes: 1 addition & 1 deletion week-1/interpret/percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ console.log(`The percentage change is ${percentageChange}`);

// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?

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

// There are 2. On line 4 and line 5

Expand Down
4 changes: 2 additions & 2 deletions week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ console.log(result);
// b) How many function calls are there?
// There isn't any function calls.

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

// This represents how many seconds are in a minute.
// This ensures that all the minutes are accounted for, and any remainders will be formatted in seconds.
Expand All @@ -41,4 +41,4 @@ console.log(result);
// The code will work with all values for movieLength. When the result is executed with a value of 1,
// the timer will display 0(Hours):0(Minutes):1(Seconds).
// I did notice though that if I changed this number to a ridiculous number for example: 100000000000000 or 1000000000,
// it would return the same value, which it should not
// it would return the same value, which it should not
1 change: 1 addition & 0 deletions week-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ console.log(`£${pounds}.${pence}`);

// 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
// const penceString = "399p": initialises a string variable with the value "399p"
Expand Down
6 changes: 3 additions & 3 deletions week-2/errors/0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
// write down the error you predict will be raised
// then call the function capitalise with a string input
// 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)}`;
Expand Down
4 changes: 2 additions & 2 deletions week-2/errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// Write down the error you predict will be raised
// Why will an error occur when this program runs?
// Try playing computer with the example to work out what is going on
// Play computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
Expand Down
2 changes: 1 addition & 1 deletion week-2/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// Predict and explain first...

// 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;
Expand Down
8 changes: 4 additions & 4 deletions week-2/implement/bmi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Below are the steps for how BMI is calculated
// Below are the steps to calculate BMI for an adult

// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.

Expand All @@ -8,8 +8,8 @@
// dividing 70 by 2.99 = 23.41
// Your result will be displayed to 1 decimal place, for example 23.4.

// You will need to implement a function that calculates the BMI of someone based off their weight and height
// Implement a function that calculates the BMI of someone using their weight and height

// Given someone's weight in kg and height in metres
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place
// When we call this function with the weight and height
// Then it returns their Body Mass Index to 1 decimal place
14 changes: 8 additions & 6 deletions week-2/implement/cases.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// A set of words can be grouped together in different cases.
// A set of words can be written grouped together in different cases.

// For example, "hello there" in snake case would be written "hello_there"
// UPPER_SNAKE_CASE means taking a string and writing it in
// UPPER_SNAKE_CASE means taking a string and writing it in all capitals with underscores for spaces

// Implement a function that:

// Given a string input like "hello there"
// When we call this function with the input string
// it returns the string in UPPER_CAMEL_CASE, so "HELLO_THERE"
// Then it returns the string in UPPER_CAMEL_CASE, so "HELLO_THERE"

// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS"
// Test case: we expect "lord of the rings" to be "LORD_OF_THE_RINGS"
// Test case: we expect "the great gatsby" to be "THE_GREAT_GATSBY"
// Test case: we expect "the da vinci code" to be "THE_DA_VINCI_CODE"

// You will need to come up with an appropriate name for the function
// Use the string documentation to help you find a solution
// Come up with a clear, simple name for the function
// Use the string documentation to help you plan your solution
9 changes: 4 additions & 5 deletions week-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// In week-1, there is a program written in interpret/to-pounds.js
// Find to-pounds.js in an earlier week in this repo

// You will need to take this code and turn it into a reusable block of code.
// You will need to declare a function called toPounds with an appropriately named parameter.

// You should call this function a number of times to check it works for different inputs
// Take this code and turn it into a reusable block of code.
// Declare a function called toPounds with an appropriately named parameter.
// Call this function a number of times to check it works for different inputs
8 changes: 4 additions & 4 deletions week-2/implement/vat.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// If products or services are subject to the 20% standard rate of VAT:
// You must add 20% to the price you charge for the goods or service.
// When selling goods, most are subject to the 20% standard rate of VAT.
// You must add 20% to the price you charge for the goods.
// You can do this by multiplying the price you charge by 1.2.
// For example, if your business sells sports equipment for £50, you multiply £50 by 1.2 for a total VAT inclusive price of £60.

// Implement a function that calculates the new price with VAT (Value Added Tax) added on
// Implement a function that calculates the new price with VAT (Value Added Tax) added on.

// Given a number,
// When I call this function with a number
// it returns the new price with VAT added on
// Then it returns the new price with VAT added on
27 changes: 17 additions & 10 deletions week-2/interpret/time-format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function pad(num) {
return num.toString().padStart(2, "0");
if (num < 10) {
return `0${num}`;
}
return num;
}

function formatTimeDisplay(seconds) {
Expand All @@ -14,23 +17,27 @@ function formatTimeDisplay(seconds) {
)}`;
}

console.log(formatTimeDisplay(61));
console.log(formatTimeDisplay(143));

// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
// You can play computer with this example
// Use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
// to help you answer these questions

// Questions

// a) Run this program with node, identify the line the error is thrown. Explain why this error is occurring. How can you fix this error?
// a) When formatTimeDisplay is called how many times will pad be called?

// b) When formatTimeDisplay is called how many times will pad be called?
// Call formatTimeDisplay with an input of 143, now answer the following:

// Call formatTimeDisplay with an input of 61, now answer the following:
// b) What value is assigned to the parameter num when pad is called for the first time?

// c) What is the value assigned to num when pad is called for the first time?
// c) What is the return value of pad when it is called for the first time?

// d) What is the return value of pad is called for the first time?
// d) What is the value assigned to the parameter num when pad
// is called for the last time in this program? Explain your answer

// e) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// e) What is the return value when pad is called
// for the last time in this program? Explain your answer

// f) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// f) Research an alternative way of padding the numbers in this code.
// Look up the string functions on mdn
10 changes: 8 additions & 2 deletions week-2/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

## Errors

In this section, you need to go to each file in `errors` directory and run the file with node to check what the error is. Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution.
In this section, you need to locate each file in the `errors` directory and run the file with node to check what the error is, like this:

```node
node errors/0.js
```

Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution.

## Debug

In this section, you need to go to each file in `debug` to **explain and predict** why the program isn't behaving as intended. Then you'll need to run the program with node to check your prediction. You will also need to correct the code too.

## Implement

In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements.Make sure you check your function works for a number of different inputs.
In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements. Make sure you check your function works for a number of different inputs.
Here is a recommended order:

1. `to-pounds.js`
Expand Down
6 changes: 1 addition & 5 deletions week-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Implement a function getAngleType
// Implement a function getAngleType, and tests for each of the acceptance criteria.

// Acceptance criteria:

// Given an angle in degrees,
// When the function getAngleType is called with this angle,
// Then it should:

// Identify Right Angles:
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"
Expand Down
4 changes: 2 additions & 2 deletions week-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// Then it should return the numerical card value

// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "9",
// Given a card with a rank between "2" and "10",
// When the function is called with such a card,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).

// Handle Face Cards (J, Q, K):
// Given a card with a rank of "10," "J," "Q," or "K",
// Given a card with a rank of "J," "Q," or "K",
// When the function is called with such a card,
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.

Expand Down
1 change: 1 addition & 0 deletions week-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.

// These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator.
9 changes: 5 additions & 4 deletions week-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// STRETCH Implement a function isValidTriangle
// Terms
// Implement a function isValidTriangle

// 🗝️ Terms
// the Triangle Inequality says: the sum of any two sides is always greater than the third side.
// practical examples:
// Side a = 3
Expand All @@ -11,8 +12,8 @@
// It's also true that b + c > a
// It's also true that a + c > b

// In our function isValidTriangle, we need to invalidate any triangle where the sum of any two sides is less than or equal to the length of the third side.
// and we need to validate any triangle where the sum of any two sides is greater than the length of the third side.
// In our function isValidTriangle, we need to return false for any triangle where the sum of any two sides is less than or equal to the length of the third side.
// and we need to return true for any triangle where the sum of any two sides is greater than the length of the third side.

// Acceptance criteria:

Expand Down
5 changes: 4 additions & 1 deletion week-3/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ Here is a recommended order:

## 💪 Stretch

Implement `rotateChar` as defined in `implement/rotate-char`
Raise a PR with your work so far before tackling the **stretch** tasks.
After you've raised a PR, have a go at:

Implement `rotateChar` as defined in the `stretch` directory.
3 changes: 2 additions & 1 deletion week-3/refactor/format-as-12-hours.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// There is an implementation of format-as-12-hours.js in the debug directory
// This implementation currently uses the expression Number(time.slice(0, 2)) twice
// Copy that implementation in here, and improve it:
// That implementation currently uses the expression Number(time.slice(0, 2)) twice
// Store this expression in a variable and reference it twice in the function in the correct place

// Explain why it makes more sense to store this expression in a variable
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// it rotates the character by the specified shift value within the alphabet,
// considering wrapping around if necessary. Non-letter characters are returned unchanged.

// This function is commonly used for text encryption and decryption,
// This function is commonly used for weak text encryption and decryption,
// where shifting characters by a certain value can obscure their meaning or reveal hidden messages.

// Acceptance criteria:
Expand All @@ -17,7 +17,7 @@
// When the function is called with these inputs,
// Then it should rotate the lowercase letter by shift positions within the lowercase alphabet, wrapping around if necessary, and return the rotated lowercase letter as a string.
console.log(rotateCharacter("a", 3)); // Output: "d"
console.log(rotateCharacter("f", 1)); // Output: "f"
console.log(rotateCharacter("f", 1)); // Output: "g"

// Scenario: Rotate Uppercase Letters:
// Given an uppercase letter character (char) and a positive integer shift,
Expand Down
2 changes: 1 addition & 1 deletion week-4/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Given the input string str,
// And a character char that may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'),
// When the function is called with these inputs,
// Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa').
// Then it should correctly count consecutive occurrences of char (e.g., 'a' appears five times in 'aaaaa').

// Scenario: No Occurrences
// Given the input string str,
Expand Down
2 changes: 1 addition & 1 deletion week-4/implement/is-prime.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Given a positive integer num,
// When the isPrime function is called with num as input,
// Then it should check if the num is prime
// Then it should return a boolean representing whether the num is prime
2 changes: 1 addition & 1 deletion week-4/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Keep running `npm test` to check the new tests you've created.

## 🔍 Investigate

In this exercise, you'll need to **play computer** with the function `find`. This function makes use of while loop statement. Your task will be to step through the code to figure out what is happening when the computer executes the code.
In this exercise, you'll need to **play computer** with the function `find`. This function makes use of a while loop statement. Your task will be to step through the code to figure out what is happening when the computer executes the code.

## 🔧 Implement

Expand Down

0 comments on commit fbfe16a

Please sign in to comment.