diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js deleted file mode 100644 index 117bcb2b6e..0000000000 --- a/Sprint-1/1-key-exercises/1-count.js +++ /dev/null @@ -1,6 +0,0 @@ -let count = 0; - -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 diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js deleted file mode 100644 index 964c9563c6..0000000000 --- a/Sprint-1/1-key-exercises/2-initials.js +++ /dev/null @@ -1,10 +0,0 @@ -const firstName = "Creola"; -const middleName = "Katherine"; -const lastName = "Johnson"; - -// Declare a variable called initials that stores the first character of each string. -// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. - -const initials = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js deleted file mode 100644 index ab90ebb28e..0000000000 --- a/Sprint-1/1-key-exercises/3-paths.js +++ /dev/null @@ -1,23 +0,0 @@ -// 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 -// Create a variable to store the ext part of the variable - -const dir = ; -const ext = ; - -// https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js deleted file mode 100644 index 292f83aabb..0000000000 --- a/Sprint-1/1-key-exercises/4-random.js +++ /dev/null @@ -1,9 +0,0 @@ -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 diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js deleted file mode 100644 index cf6c5039f7..0000000000 --- a/Sprint-1/2-mandatory-errors/0.js +++ /dev/null @@ -1,2 +0,0 @@ -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? \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js deleted file mode 100644 index 7a43cbea76..0000000000 --- a/Sprint-1/2-mandatory-errors/1.js +++ /dev/null @@ -1,4 +0,0 @@ -// trying to create an age variable and then reassign the value by 1 - -const age = 33; -age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js deleted file mode 100644 index e09b89831d..0000000000 --- a/Sprint-1/2-mandatory-errors/2.js +++ /dev/null @@ -1,5 +0,0 @@ -// 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"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js deleted file mode 100644 index ec101884db..0000000000 --- a/Sprint-1/2-mandatory-errors/3.js +++ /dev/null @@ -1,9 +0,0 @@ -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 -// Before running the code, make and explain a prediction about why the code won't work -// Then run the code and see what error it gives. -// Consider: Why does it give this error? Is this what I predicted? If not, what's different? -// Then try updating the expression last4Digits is assigned to, in order to get the correct value diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js deleted file mode 100644 index 5f86c730bc..0000000000 --- a/Sprint-1/2-mandatory-errors/4.js +++ /dev/null @@ -1,2 +0,0 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js deleted file mode 100644 index e24ecb8e18..0000000000 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ /dev/null @@ -1,22 +0,0 @@ -let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; - -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; - -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 - -// 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 - -// d) Identify all the lines that are variable declarations - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js deleted file mode 100644 index 47d2395587..0000000000 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ /dev/null @@ -1,25 +0,0 @@ -const movieLength = 8784; // length of movie in seconds - -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; - -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; - -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -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? - -// b) How many function calls are there? - -// c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? - -// e) What do you think the variable result represents? Can you think of a better name for this variable? - -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js deleted file mode 100644 index 60c9ace69a..0000000000 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ /dev/null @@ -1,27 +0,0 @@ -const penceString = "399p"; - -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"); - -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 - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md deleted file mode 100644 index 962580b828..0000000000 --- a/Sprint-1/4-stretch-explore/chrome.md +++ /dev/null @@ -1,15 +0,0 @@ -Open a new window in Chrome, right click an empty space on the page, select **Inspect** from the dropdown, then locate the **Console** tab. - -Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). -Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. - -Let's try an example. - -In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; - -What effect does calling the `alert` function have? - -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`? diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md deleted file mode 100644 index 0216dee56a..0000000000 --- a/Sprint-1/4-stretch-explore/objects.md +++ /dev/null @@ -1,16 +0,0 @@ -## Objects - -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. - -Open the Chrome devtools Console, type in `console.log` and then hit enter - -What output do you get? - -Now enter just `console` in the Console, what output do you get back? - -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? diff --git a/Sprint-1/readme.md b/Sprint-1/readme.md deleted file mode 100644 index 62d24c9580..0000000000 --- a/Sprint-1/readme.md +++ /dev/null @@ -1,35 +0,0 @@ -# 🧭 Guide to Week 1 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/1/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you _how_ to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -This README will guide you through the different sections for this week. - -## 1 Exercises - -In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 2 Errors - -In this section, you'll 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. - -## 3 Interpret - -In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. - -You must use documentation to make sense of anything unfamiliar - learning how to look things up this way is a fundamental part of being a developer! - -You can also use `console.log` to check the value of different variables in the code. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 4 Explore - Stretch 💪 - -This stretch activity will get you to start exploring new concepts and environments by yourself. It will do so by prompting you to reflect on some questions. diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js deleted file mode 100644 index 653d6f5a07..0000000000 --- a/Sprint-2/1-key-errors/0.js +++ /dev/null @@ -1,13 +0,0 @@ -// Predict and explain first... -// =============> write your prediction here - -// call the function capitalise with a string input -// interpret the error message and figure out why an error is occurring - -function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} - -// =============> write your explanation here -// =============> write your new code here diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js deleted file mode 100644 index f2d56151f4..0000000000 --- a/Sprint-2/1-key-errors/1.js +++ /dev/null @@ -1,20 +0,0 @@ -// Predict and explain first... - -// Why will an error occur when this program runs? -// =============> write your prediction here - -// Try playing 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(decimalNumber); - -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js deleted file mode 100644 index aad57f7cfe..0000000000 --- a/Sprint-2/1-key-errors/2.js +++ /dev/null @@ -1,20 +0,0 @@ - -// Predict and explain first BEFORE you run any code... - -// this function should square any number but instead we're going to get an error - -// =============> write your prediction of the error here - -function square(3) { - return num * num; -} - -// =============> write the error message here - -// =============> explain this error message here - -// Finally, correct the code to fix the problem - -// =============> write your new code here - - diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js deleted file mode 100644 index b27511b417..0000000000 --- a/Sprint-2/2-mandatory-debug/0.js +++ /dev/null @@ -1,14 +0,0 @@ -// Predict and explain first... - -// =============> write your prediction here - -function multiply(a, b) { - console.log(a * b); -} - -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); - -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js deleted file mode 100644 index 37cedfbcfd..0000000000 --- a/Sprint-2/2-mandatory-debug/1.js +++ /dev/null @@ -1,13 +0,0 @@ -// Predict and explain first... -// =============> write your prediction here - -function sum(a, b) { - return; - a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js deleted file mode 100644 index 57d3f5dc35..0000000000 --- a/Sprint-2/2-mandatory-debug/2.js +++ /dev/null @@ -1,24 +0,0 @@ -// Predict and explain first... - -// Predict the output of the following code: -// =============> Write your prediction here - -const num = 103; - -function getLastDigit() { - 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)}`); - -// Now run the code and compare the output to your prediction -// =============> write the output here -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here - -// This program should tell the user the last digit of each number. -// Explain why getLastDigit is not working properly - correct the problem diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js deleted file mode 100644 index 58b1085f1f..0000000000 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ /dev/null @@ -1,19 +0,0 @@ -// Below are the steps for how BMI is calculated - -// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. - -// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: - -// squaring your height: 1.73 x 1.73 = 2.99 -// 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 - -// Given someone's weight in kg and height in metres -// Then when we call this function with the weight and height -// It should return a string of their Body Mass Index to 1 decimal place - -function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js deleted file mode 100644 index 5b0ef77ad9..0000000000 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ /dev/null @@ -1,16 +0,0 @@ -// A set of words can be 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 all caps with underscores instead of 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_SNAKE_CASE, so "HELLO_THERE" - -// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" - -// You will need to come up with an appropriate name for the function -// Use the MDN string documentation to help you find a solution -// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js deleted file mode 100644 index 10754da73f..0000000000 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ /dev/null @@ -1,6 +0,0 @@ -// In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js - -// 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 diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js deleted file mode 100644 index c0dd9c9a5b..0000000000 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ /dev/null @@ -1,38 +0,0 @@ -function pad(num) { - let numString = num.toString(); - while (numString.length < 2) { - numString = "0" + numString; - } - return numString; -} - -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; - - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; -} - -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit -// to help you answer these questions - -// Questions - -// a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here - -// Call formatTimeDisplay with an input of 61, now answer the following: - -// b) What is the value assigned to num when pad is called for the first time? -// =============> write your answer here - -// c) What is the return value of pad when it is called for the first time? -// =============> write your answer here - -// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here - -// e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js deleted file mode 100644 index 32a32e66b8..0000000000 --- a/Sprint-2/5-stretch-extend/format-time.js +++ /dev/null @@ -1,25 +0,0 @@ -// This is the latest solution to the problem from the prep. -// Make sure to do the prep before you do the coursework -// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. - -function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; - } - return `${time} am`; -} - -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); diff --git a/Sprint-2/readme.md b/Sprint-2/readme.md deleted file mode 100644 index 44c118e338..0000000000 --- a/Sprint-2/readme.md +++ /dev/null @@ -1,41 +0,0 @@ -# 🧭 Guide to week 2 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/2/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you how to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -## 1 Errors - -In this section, you need to go to each file in `errors` directory. Read the file and predict what error will happen. Then 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. - -## 2 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. - -## 3 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. - -Here is a recommended order: - -1. `1-bmi.js` -1. `2-cases.js` -1. `3-to-pounds.js` - -## 4 Interpret - -In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. - -You must use documentation to make sense of anything unfamiliar. Learning how to look things up this way is a fundamental part of being a developer! - -You can also use `console.log` to check the value of different variables in the code. - -## 5 Extend - -In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times. - -Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. This section is not mandatory, but it will also help you solve some similar kata in Codewars. diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js deleted file mode 100644 index 970cb9b641..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ /dev/null @@ -1,33 +0,0 @@ -// Implement a function isProperFraction, -// when given two numbers, a numerator and a denominator, it should return true if -// the given numbers form a proper fraction, and false otherwise. - -// Assumption: The parameters are valid numbers (not NaN or Infinity). - -// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - -function isProperFraction(numerator, denominator) { - // TODO: Implement this function -} - -// The line below allows us to load the isProperFraction function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = isProperFraction; - -// Here's our helper again -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? - -// Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js deleted file mode 100644 index 95b6ebb7d4..0000000000 --- a/Sprint-3/2-practice-tdd/count.js +++ /dev/null @@ -1,5 +0,0 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 -} - -module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js deleted file mode 100644 index f95d71db13..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ /dev/null @@ -1,5 +0,0 @@ -function getOrdinalNumber(num) { - return "1st"; -} - -module.exports = getOrdinalNumber; diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js deleted file mode 100644 index 040769beaf..0000000000 --- a/Sprint-3/4-stretch/password-validator.js +++ /dev/null @@ -1,5 +0,0 @@ -function passwordValidator(password) { - return password.length >= 5; -} - -module.exports = passwordValidator; diff --git a/Sprint-3/3-dead-code/README.md b/dead-code/README.md similarity index 100% rename from Sprint-3/3-dead-code/README.md rename to dead-code/README.md diff --git a/Sprint-3/3-dead-code/exercise-1.js b/dead-code/exercise-1.js similarity index 100% rename from Sprint-3/3-dead-code/exercise-1.js rename to dead-code/exercise-1.js diff --git a/Sprint-3/3-dead-code/exercise-2.js b/dead-code/exercise-2.js similarity index 100% rename from Sprint-3/3-dead-code/exercise-2.js rename to dead-code/exercise-2.js diff --git a/Sprint-3/1-implement-and-rewrite-tests/README.md b/implement-and-rewrite-tests/README.md similarity index 66% rename from Sprint-3/1-implement-and-rewrite-tests/README.md rename to implement-and-rewrite-tests/README.md index 4658c9423a..b7ad016b20 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/README.md +++ b/implement-and-rewrite-tests/README.md @@ -8,7 +8,7 @@ to choose test values that thoroughly test a function. In the `implement` directory you've got a number of functions you'll need to implement. For each function, you also have a number of different cases you'll need to check for your function. -Write your implementation and your tests to cover the cases the function should fulfil. +Write your implementation and your tests to cover the cases the function should fulfil. Write tests in the relevant files in the `implement-tests-with-node-test` directory. Here is a recommended order: @@ -18,19 +18,19 @@ Here is a recommended order: ## 2 Rewrite tests with Jest -`console.log` is most often used as a debugging tool. We use to inspect the state of our program during runtime. - -We can use `console.assert` to write assertions: however, it is not very easy to use when writing large test suites. In the first section, Implement, we used a custom "helper function" to make our assertions more readable. - Jest is a whole library of helper functions we can use to make our assertions more readable and easier to write. -Your new task is to write the same tests as you wrote in the `implement` directory, but using Jest instead of `console.assert`. +Your new task is to write the same tests as you wrote in the `implement-tests-with-node-test` directory, but using Jest instead of `node:test`. You shouldn't have to change the contents of `implement` to write these tests. There are files for your Jest tests in the `rewrite-tests-with-jest` directory. They will automatically use the functions you already implemented. -You can run all the tests in this repo by running `npm test` in your terminal. However, VSCode has a built-in test runner that you can use to run the tests, and this should make it much easier to focus on building up your test cases one at a time. +There are few ways you can run these tests: +* For `node:test` tests, you can run them in the terminal with `node path/to/file`. +* To run all of the tests in this repo, you can run `npm test`. +* To run just one directory or file of tests, you can run `npm test implement-and-rewrite-tests/rewrite-tests-with-jest` or `implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js`. +* VSCode has a built-in test runner that you can use to run the tests, and this should make it much easier to focus on building up your test cases one at a time. https://code.visualstudio.com/docs/editor/testing @@ -42,6 +42,3 @@ https://code.visualstudio.com/docs/editor/testing ![VSCode Test Runner](../../run-this-test.png) ![Test Results](../../test-results-output.png) - -> [!TIP] -> You can always run a single test file by running `npm test path/to/test-file.test.js`. diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js new file mode 100644 index 0000000000..cf50f6cade --- /dev/null +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -0,0 +1,12 @@ +import assert from "node:assert"; +import test from "node:test"; + +import { getAngleType } from "../implement/1-get-angle-type.js"; + +// TODO: Write tests to cover all cases, including boundary and invalid cases. +// Example: Identify Right Angles + +test("Classifies right angles", () => { + const right = getAngleType(90); + assert.equal(right, "Right angle"); +}); diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js new file mode 100644 index 0000000000..a290846058 --- /dev/null +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -0,0 +1,12 @@ +import assert from "node:assert"; +import test from "node:test"; + +import { isProperFraction } from "../implement/2-is-proper-fraction.js"; + +// TODO: Write tests to cover all cases. +// What combinations of numerators and denominators should you test? + +test("Basic proper fraction", () => { + // Example: 1/2 is a proper fraction + assert.equal(isProperFraction(1, 2), true); +}); diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js new file mode 100644 index 0000000000..f5092d9b10 --- /dev/null +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js @@ -0,0 +1,16 @@ +import assert from "node:assert"; +import test from "node:test"; + +import { getCardValue } from "../implement/3-get-card-value.js"; + +// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. + +test("Valid single-digit card", () => { + assert.equal(getCardValue("9♠"), 9); +}); + +test("Arbitrary non-card string", () => { + assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error"); +}); + +// TODO: What other invalid card cases can you think of? diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js similarity index 51% rename from Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js rename to implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..8a6fba0504 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -1,5 +1,7 @@ // Implement a function getAngleType // +// Don't forget to write tests in implement-tests-with-node-test. +// // When given an angle in degrees, it should return a string indicating the type of angle: // - "Acute angle" for angles greater than 0° and less than 90° // - "Right angle" for exactly 90° @@ -14,24 +16,6 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -function getAngleType(angle) { +export function getAngleType(angle) { // TODO: Implement this function } - -// The line below allows us to load the getAngleType function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = getAngleType; - -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js new file mode 100644 index 0000000000..f983800f00 --- /dev/null +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -0,0 +1,18 @@ +// Implement a function isProperFraction, +// +// Don't forget to write tests in implement-tests-with-node-test. +// +// When given two numbers, a numerator and a denominator, it should return true if +// the given numbers form a proper fraction, and false otherwise. + +// Assumption: The parameters are valid numbers (not NaN or Infinity). + +// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. + +// Acceptance criteria: +// After you have implemented the function, write tests to cover all the cases, and +// execute the code to ensure all tests pass. + +export function isProperFraction(numerator, denominator) { + // TODO: Implement this function +} diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js similarity index 55% rename from Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js rename to implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..9614ab1ee9 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -1,5 +1,7 @@ // This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck +// Don't forget to write tests in implement-tests-with-node-test. + // Implement a function getCardValue, when given a string representing a playing card, // should return the numerical value of the card. @@ -21,34 +23,6 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -function getCardValue(card) { +export function getCardValue(card) { // TODO: Implement this function } - -// The line below allows us to load the getCardValue function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = getCardValue; - -// Helper functions to make our assertions easier to read. -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); - -// Handling invalid cards -try { - getCardValue("invalid"); - - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid card 😢"); -} catch (e) { - console.log("Error thrown for invalid card 🎉"); -} - -// What other invalid card cases can you think of? diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js similarity index 69% rename from Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js rename to implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..e0ba786ab3 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -1,6 +1,4 @@ -// This statement loads the getAngleType function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const getAngleType = require("../implement/1-get-angle-type"); +import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests in Jest syntax to cover all cases/outcomes, // including boundary and invalid cases. diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js similarity index 52% rename from Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js rename to implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba1..5d49e2d8bb 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -1,6 +1,4 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const isProperFraction = require("../implement/2-is-proper-fraction"); +import { isProperFraction } from "../implement/2-is-proper-fraction.js"; // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js similarity index 68% rename from Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js rename to implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2e..a6de5a82a4 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -1,6 +1,4 @@ -// This statement loads the getCardValue function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const getCardValue = require("../implement/3-get-card-value"); +import { getCardValue } from "../implement/3-get-card-value.js"; // TODO: Write tests in Jest syntax to cover all possible outcomes. diff --git a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md b/implement-and-rewrite-tests/testing-guide.md similarity index 100% rename from Sprint-3/1-implement-and-rewrite-tests/testing-guide.md rename to implement-and-rewrite-tests/testing-guide.md diff --git a/package.json b/package.json index 0657e22dd8..6ae16268ce 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,9 @@ "version": "1.0.0", "description": "Like learning a musical instrument, programming requires daily practice.", "main": "index.js", + "type": "module", "scripts": { - "test": "jest" + "test": "node --experimental-vm-modules ./node_modules/.bin/jest" }, "keywords": [], "author": "Code Your Future", diff --git a/Sprint-3/2-practice-tdd/README.md b/practice-tdd/README.md similarity index 100% rename from Sprint-3/2-practice-tdd/README.md rename to practice-tdd/README.md diff --git a/practice-tdd/count.js b/practice-tdd/count.js new file mode 100644 index 0000000000..5518c57123 --- /dev/null +++ b/practice-tdd/count.js @@ -0,0 +1,3 @@ +export function countChar(stringOfCharacters, findCharacter) { + return 5 +} diff --git a/Sprint-3/2-practice-tdd/count.test.js b/practice-tdd/count.test.js similarity index 95% rename from Sprint-3/2-practice-tdd/count.test.js rename to practice-tdd/count.test.js index 179ea0ddf7..cb3aaae591 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -1,5 +1,5 @@ // implement a function countChar that counts the number of times a character occurs in a string -const countChar = require("./count"); +import { countChar } from "./count.js"; // Given a string `str` and a single character `char` to search for, // When the countChar function is called with these inputs, // Then it should: diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js new file mode 100644 index 0000000000..5c6291f5ed --- /dev/null +++ b/practice-tdd/get-ordinal-number.js @@ -0,0 +1,3 @@ +export function getOrdinalNumber(num) { + return "1st"; +} diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js similarity index 94% rename from Sprint-3/2-practice-tdd/get-ordinal-number.test.js rename to practice-tdd/get-ordinal-number.test.js index adfa58560f..e23174a187 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -1,4 +1,4 @@ -const getOrdinalNumber = require("./get-ordinal-number"); +import { getOrdinalNumber } from "./get-ordinal-number.js"; // In this week's prep, we started implementing getOrdinalNumber. // Continue testing and implementing getOrdinalNumber for additional cases. diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js similarity index 84% rename from Sprint-3/2-practice-tdd/repeat-str.js rename to practice-tdd/repeat-str.js index 2af0a2cea7..af273f3b01 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,7 +1,5 @@ -function repeatStr() { +export function repeatStr() { // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). // The goal is to re-implement that function, not to use it. return "hellohellohello"; } - -module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js similarity index 96% rename from Sprint-3/2-practice-tdd/repeat-str.test.js rename to practice-tdd/repeat-str.test.js index a3fc1196c4..8a7036102b 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -1,5 +1,5 @@ // Implement a function repeatStr -const repeatStr = require("./repeat-str"); +import { repeatStr } from "./repeat-str.js"; // Given a target string `str` and a positive integer `count`, // When the repeatStr function is called with these inputs, // Then it should: diff --git a/Sprint-3/4-stretch/README.md b/sprint-3-stretch-exercises/README.md similarity index 100% rename from Sprint-3/4-stretch/README.md rename to sprint-3-stretch-exercises/README.md diff --git a/Sprint-3/4-stretch/card-validator.md b/sprint-3-stretch-exercises/card-validator.md similarity index 100% rename from Sprint-3/4-stretch/card-validator.md rename to sprint-3-stretch-exercises/card-validator.md diff --git a/Sprint-3/4-stretch/find.js b/sprint-3-stretch-exercises/find.js similarity index 100% rename from Sprint-3/4-stretch/find.js rename to sprint-3-stretch-exercises/find.js diff --git a/sprint-3-stretch-exercises/password-validator.js b/sprint-3-stretch-exercises/password-validator.js new file mode 100644 index 0000000000..ac70324a56 --- /dev/null +++ b/sprint-3-stretch-exercises/password-validator.js @@ -0,0 +1,3 @@ +export function isValidPassword(password) { + return password.length >= 5; +} diff --git a/Sprint-3/4-stretch/password-validator.test.js b/sprint-3-stretch-exercises/password-validator.test.js similarity index 92% rename from Sprint-3/4-stretch/password-validator.test.js rename to sprint-3-stretch-exercises/password-validator.test.js index 8fa3089d6b..2a58a0fb69 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/sprint-3-stretch-exercises/password-validator.test.js @@ -14,7 +14,7 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ -const isValidPassword = require("./password-validator"); +import { isValidPassword } from "./password-validator.js"; test("password has at least 5 characters", () => { // Arrange const password = "12345";