# JavaScript Exercises
These JavaScript exercises are intended to complement the JavaScript content on [The Odin Project](https://www.theodinproject.com/) (TOP). They should only be done when instructed during the course of the curriculum.
## Contributing
If you have a suggestion to improve an exercise, an idea for a new exercise, or notice an issue with an exercise, please feel free to open an issue after thoroughly reading our [contributing guide](https://github.com/TheOdinProject/.github/blob/main/CONTRIBUTING.md).
## How To Use These Exercises
1. Fork and clone this repository. To learn how to fork a repository, see the GitHub documentation on how to [fork a repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo).
- Copies of repositories on your machine are called clones. If you need help cloning to your local environment you can learn how from the GitHub documentation on [cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository).
1. Before you start working on any exercises, you should first ensure you have the following installed:
- **NPM**. You should have installed NPM already in our [Installing Node.js](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/installing-node-js) lesson. Just in case you need to check, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, **do not follow the instructions in the terminal** to install with `apt-get` as this causes permission issues. Instead, go back to the installation lesson and install Node with NVM by following the instructions there.
- **Jest**. After cloning this repository to your local machine and installing NPM, go into the newly created directory (`cd javascript-exercises`) and run `npm install`. This will install Jest and set up the testing platform based on our preconfigured settings. (Note: if you get warnings that packages are out of date or contain vulnerabilities, you can safely ignore them for these exercises.)
1. Each exercise includes the following:
- A markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests.
- A `solutions` directory that contains a solution and the same test file with all of the tests unskipped.
To complete an exercise, you will need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. When you run a test for the first time, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass.
1. Some of the exercises have test conditions defined in their spec file as `test.skip` instead of `test`. This is intentional. Once all `test`s pass, you will change the next `test.skip` to `test` and test your code again. You will do this until all conditions are satisfied. **All tests must pass at the same time**, and you should not have any instances of `test.skip` in the spec file when you are finished with an exercise.
1. Once you successfully finish an exercise, check the `solutions` directory within each exercise to compare it with yours.
- You should not be checking the solution for an exercise until you finish it!
- If your solution differs wildly from TOP's solution (and still passes the exercise's requirements), that is completely fine. Feel free to ask about it in our Discord if there are parts you do not understand.
> [!IMPORTANT]
> Do not submit your solutions to this repo, as any PRs that do so will be closed without merging.
> [!NOTE]
> Due to the way Jest handles failed tests, it may return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
The first exercise, `helloWorld`, will walk you through the process in-depth.
## Debugging
To debug functions, you can run the tests in the Visual Studio Code debugger terminal. You can open this by clicking the "Run and Debug" icon on the left or pressing <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>D</kbd>, then clicking JavaScript Debug Terminal. You will be able to set breakpoints as you would in the Chrome DevTools debugger. You can run `npm test exerciseName.spec.js` to then execute your code up until your breakpoint and step through your code as necessary. **NOTE**: To take advantage of the debugger, you **MUST** run the script in the debugger terminal, not the bash or zsh terminal.
## Adding a new exercise
To add a new exercise:
1. Be sure to run `npm install` at the root of the `javascript-exercises` directory.
2. Run the command `npm run generate`.
3. When prompted, enter the name of the new exercise in "camelCase" syntax.
After entering an exercise name, a new directory with the necessary files will be created. You will then need to update the `README.md` and `spec.js` files as well as the files in the `solution` directory of the new exercise.
没有合适的资源?快使用搜索试试~ 我知道了~
一系列 JavaScript 练习
共120个文件
js:65个
md:19个
sample:13个
1 下载量 62 浏览量
2024-11-04
23:33:12
上传
评论
收藏 5.38MB ZIP 举报
温馨提示
这些练习与 The Odin Project 的课程紧密结合,能够有效地补充课程内容,帮助学习者更好地理解和掌握 JavaScript 知识。每个练习都包含详细的任务描述、空的 JavaScript 文件和测试用例,这种结构有助于学习者逐步实现功能并通过测试来验证代码的正确性,具有很强的引导性。测试框架 Jest 的集成使得测试过程方便快捷,并且可以通过观察测试结果来调试代码,提高开发效率。此外,提供了调试方法,如在 Visual Studio Code 中使用调试终端进行断点调试,方便学习者查找和解决代码中的问题。 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
资源推荐
资源详情
资源评论
收起资源包目录
一系列 JavaScript 练习 (120个子文件)
config 317B
description 73B
.eslintignore 21B
exclude 240B
.gitignore 35B
HEAD 210B
HEAD 210B
HEAD 30B
HEAD 21B
pack-22146525aa7a0728bb60f8f2ea7425fba7fe82d9.idx 165KB
index 11KB
calculator.spec.js 2KB
calculator-solution.spec.js 2KB
pigLatin-solution.spec.js 2KB
pigLatin.spec.js 2KB
repeatString.spec.js 2KB
repeatString-solution.spec.js 2KB
plopFile.js 2KB
findTheOldest.spec.js 1KB
findTheOldest-solution.spec.js 1KB
findTheOldest-solution.js 1KB
writeExerciseSpec.js 1KB
removeFromArray.spec.js 1KB
fibonacci.spec.js 1KB
removeFromArray-solution.spec.js 1KB
fibonacci-solution.spec.js 1KB
palindromes.spec.js 1KB
removeFromArray-solution.js 1KB
palindromes-solution.spec.js 1024B
helpers.js 943B
snakeCase-solution.spec.js 873B
snakeCase.spec.js 860B
fibonacci-solution.js 859B
sumAll.spec.js 849B
sumAll-solution.spec.js 829B
caesar-solution.js 766B
palindromes-solution.js 765B
caesar.spec.js 750B
tempConversion.spec.js 748B
tempConversion-solution.spec.js 743B
caesar-solution.spec.js 730B
writeExercise.js 724B
leapYears.spec.js 696B
leapYears-solution.spec.js 681B
sumAll-solution.js 635B
calculator-solution.js 613B
reverseString.spec.js 593B
reverseString-solution.spec.js 587B
pigLatin-solution.js 577B
writeReadme.js 489B
snakeCase-solution.js 429B
leapYears-solution.js 369B
getTheTitles.spec.js 352B
calculator.js 348B
getTheTitles-solution.spec.js 347B
tempConversion-solution.js 300B
repeatString-solution.js 220B
helloWorld-solution.spec.js 205B
helloWorld.spec.js 194B
tempConversion.js 193B
reverseString-solution.js 129B
getTheTitles-solution.js 122B
removeFromArray.js 111B
reverseString.js 109B
findTheOldest.js 109B
repeatString.js 107B
getTheTitles.js 107B
palindromes.js 106B
leapYears.js 101B
snakeCase.js 101B
fibonacci.js 101B
pigLatin.js 99B
helloWorld-solution.js 97B
sumAll.js 95B
caesar.js 95B
helloWorld.js 82B
package-lock.json 267KB
package.json 1KB
.eslintrc.json 206B
LICENSE 1KB
main 210B
main 41B
README.md 5KB
README.md 3KB
bug_report.md 2KB
PULL_REQUEST_TEMPLATE.md 2KB
feature_request.md 2KB
README.md 1KB
README.md 1KB
README.md 1009B
README.md 1007B
README.md 740B
README.md 740B
README.md 725B
README.md 712B
README.md 680B
README.md 672B
README.md 531B
README.md 529B
README.md 511B
共 120 条
- 1
- 2
资源评论
pk_xz123456
- 粉丝: 2167
- 资源: 1837
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功