- Notifications
You must be signed in to change notification settings - Fork167
techreturners/js_coding_exercises
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository contains 8 sets of exercises which will help you to build your ability and confidence with JavaScript. Completing all 8 sets would be ideal, but please ensure you complete at least the first 6.
We will be checking over your solutions, so please ensure youcommit
after solving each problem, and don't forget topush
to GitHub regularly.
You may find these exercises challenging but they give you the opportunity to showcase your Growth Mindset and commitment to programming and learning. You can always come to us if you are having any trouble! 😊
If you need reminding of any key Javascript concepts to solve these challenges we recommend the 'Codecademy: Learn Javascript' (free) course:https://www.codecademy.com/learn/introduction-to-javascript
NOTE: You are not required to purchase any PRO content from codecademy.
We also recommend this visual guide if you are unfamiliar with GitHub:https://agripongit.vincenttunru.com/
Remember to break down problems to help you solve them and that Google is your friend!
To complete these challenges you will need to have Node.js installed on your computer. Follow this link and click on the green button to install for Mac or Windows:https://nodejs.org/en/download/
👉 We recommend using the most recent LTS (Long-Term Support) version of Node.
A download will start. When a pop-up appears please follow the installation instructions.
To check you have installed Node.js correctly, go to your terminal and type:
node --version
Your terminal should respond with the version of Node you have installed. It will look something similar to the following:
v18.12.1
🔍 Don't worry if you don't see the exact same version of Node 18. However, we recommend you use Node 18.x.x during this programme, as it is the current LTS (long-term supported) version as of Oct 2023.
Once you've got Node installed you can make a start - before you do please make sure to watch thegetting started video as it walks you through instructions for getting started and the first exercise.
The short version is that you must:
👉 Use the Github website tofork
the repository into your account.
👉 Use thegit clone
commandon the forked repository in your account to make a local copy of the repository on your computer.
👉 Install the dependencies in your local copy usingnpm install
👉 Complete the challenges.
👉 Usegit add
,git commit
andgit push
to upload your work to the forked repository on your github account.
👉 Next, look inside thechallenges directory.
📗 Each JavaScript file in thechallenges has an accompanying explanation in thedocs folder, which includes handy tips and information to expand your learning.
🕵️ The first five JavaScript files have a corresponding file in thetests folder. After Exercise 005 you have to write your own tests too! 🥳
Your task is to make every test pass for each file. To run the tests, use the command:
npm test
Work through each test one by one until you have them all passing. Initially, you'll have a lot of failing tests and a lot of output on the console. To focus on a single test, you can add.only
to the test you are interested in:
describe('capitalize',()=>{test.only('returns a capitalized word',()=>{expect(capitalize('hello')).toBe('Hello');});test('does nothing if the word is already capitalized',()=>{expect(capitalize('Hello')).toBe('Hello');});test('capitalizes the first word of a sentence',()=>{expect(capitalize('the quick fox')).toBe('The quick fox');});});
.only
afterwards so you can run all your tests again.
You can also ignore tests momentarily by adding anx
at the front:
xdescribe('capitalize',()=>{test('returns a capitalized word',()=>{expect(capitalize('hello')).toBe('Hello');});test('does nothing if the word is already capitalized',()=>{expect(capitalize('Hello')).toBe('Hello');});test('capitalizes the first word of a sentence',()=>{expect(capitalize('the quick fox')).toBe('The quick fox');});});
Lastly, to runONE test file at a time you can use the commandnpm test
followed by the path to the file:
npm test test/exercise004.test.js
We have provided basic tests for each function - but can you think of any more tests which would help make sure these functions behave correctly? 🧐
Think aboutedge cases, which are use cases for your function which you might not ordinarily expect, but which you need to handle regardless.
For example, the first function should capitalize a string. So we have tested that it works for a single word:
capitalize("hello") --> "Hello"
What about a longer string:
capitalize("hello world") --> "Hello world"
And when the string is already capitalized:
capitalize("Hello everyone") --> "Hello everyone"
What if the string contains no characters?
capitalize("") --> ""
👉 Try adding extra tests to cover possibilities that the existing tests miss!
To help you write "clean", tidy code, we've included some rules forEslint in the.eslintrc
file in this repository.
Eslint helps by spotting common errors such as undefined variables. This is hugely beneficial, as it alerts you to many errors before you even run your code! It also helps you write code that will be easy for you and other developers to read in the future.
It is configured with a set of standard rules, which can be viewedhere.
For reporting as-you-type, install and enable the eslint extension for VSCode. To do this:
- Click the square symbol on the left hand bar for extensions
- Search for "eslint" and click install
Alternatively, you can manually run eslint by running this command in the root folder of this repository on your machine:
npx eslint ./
If there is no output theneslint
has found no errors 🥳 If there are errors, you should fix them before committing your code.
Openthe first challenge instructions to get started! 🙌
About
Pre-journey: A repository of JavaScript coding exercises. ✨
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.