diff --git a/.github/labels.json b/.github/labels.json index 330a995d1..a08f48068 100644 --- a/.github/labels.json +++ b/.github/labels.json @@ -1 +1 @@ -[{"name":"Improvement", "color":"0000ff", "description":"Improvement to this coursework" }] +[{"name":"Improvement", "color":"0000ff", "description":"Improvement to this coursework" }] diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 46c150e15..4216cc9f1 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,36 +1,36 @@ - - -**Volunteers: Are you marking this coursework?** _You can find a guide on how to mark this coursework in `HOW_TO_MARK.md` in the root of this repository_ - -# Your Details - -- Your Name: -- Your City: -- Your Slack Name: - -# Homework Details - -- Module: -- Week: - -# Notes - -- What did you find easy? - -- What did you find hard? - -- What do you still not understand? - -- Any other notes? + + +**Volunteers: Are you marking this coursework?** _You can find a guide on how to mark this coursework in `HOW_TO_MARK.md` in the root of this repository_ + +# Your Details + +- Your Name: +- Your City: +- Your Slack Name: + +# Homework Details + +- Module: +- Week: + +# Notes + +- What did you find easy? + +- What did you find hard? + +- What do you still not understand? + +- Any other notes? diff --git a/.github/teams.yml b/.github/teams.yml index 347c7d9c1..d9d095c9d 100644 --- a/.github/teams.yml +++ b/.github/teams.yml @@ -1,3 +1,3 @@ -Improvement: - - '@ChrisOwen101' - - 'ChrisOwen101' +Improvement: + - '@ChrisOwen101' + - 'ChrisOwen101' diff --git a/.github/workflows/close.yml b/.github/workflows/close.yml index 137dc57e9..59f4d14d1 100644 --- a/.github/workflows/close.yml +++ b/.github/workflows/close.yml @@ -1,17 +1,17 @@ -name: "Close stale issues and PRs" -on: - workflow_dispatch: - schedule: - - cron: "30 1 * * *" - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v3 - with: - stale-pr-message: "Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback." - days-before-stale: 42 - days-before-close: 0 - days-before-issue-stale: -1 - days-before-issue-close: -1 +name: "Close stale issues and PRs" +on: + workflow_dispatch: + schedule: + - cron: "30 1 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v3 + with: + stale-pr-message: "Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback." + days-before-stale: 42 + days-before-close: 0 + days-before-issue-stale: -1 + days-before-issue-close: -1 diff --git a/.github/workflows/extra-tests.yml b/.github/workflows/extra-tests.yml index 826bae048..5762e8a75 100644 --- a/.github/workflows/extra-tests.yml +++ b/.github/workflows/extra-tests.yml @@ -1,14 +1,14 @@ -name: Run extra tests -on: - pull_request: - paths: - - extra/** -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install modules - run: npm install - - name: Run extra tests - run: npm run extra-tests +name: Run extra tests +on: + pull_request: + paths: + - extra/** +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install modules + run: npm install + - name: Run extra tests + run: npm run extra-tests diff --git a/.github/workflows/mandatory-tests.yml b/.github/workflows/mandatory-tests.yml index 12c660a5a..21bbe47de 100644 --- a/.github/workflows/mandatory-tests.yml +++ b/.github/workflows/mandatory-tests.yml @@ -1,11 +1,11 @@ -name: Run mandatory tests -on: pull_request -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install modules - run: npm install - - name: Run mandatory tests - run: npm test +name: Run mandatory tests +on: pull_request +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install modules + run: npm install + - name: Run mandatory tests + run: npm test diff --git a/.github/workflows/team-labeler.yml b/.github/workflows/team-labeler.yml index eb2f8e32a..ac308305c 100644 --- a/.github/workflows/team-labeler.yml +++ b/.github/workflows/team-labeler.yml @@ -1,13 +1,13 @@ -name: "team-labeller" -on: - pull_request: - workflow_dispatch: - schedule: - - cron: "30 1 * * *" -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: JulienKode/team-labeler-action@v0.1.0 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" +name: "team-labeller" +on: + pull_request: + workflow_dispatch: + schedule: + - cron: "30 1 * * *" +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: JulienKode/team-labeler-action@v0.1.0 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.gitignore b/.gitignore index 936e5c57a..51edfb631 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/node_modules/ -/package-lock.json +/node_modules/ +/package-lock.json diff --git a/GRADING.md b/GRADING.md index b8ab587d2..2fc61fd56 100644 --- a/GRADING.md +++ b/GRADING.md @@ -1,19 +1,19 @@ - - -# Grading - -All coursework is graded using the Marking Guide found on the Syllabus. - -http://syllabus.codeyourfuture.io/guides/marking-guide - -If you have any questions on these guidelines - please ask. - -## Coding Standards - -Your code should follow our Coding Standards or it will be marked poorly. - -https://syllabus.codeyourfuture.io/guides/code-style-guide + + +# Grading + +All coursework is graded using the Marking Guide found on the Syllabus. + +http://syllabus.codeyourfuture.io/guides/marking-guide + +If you have any questions on these guidelines - please ask. + +## Coding Standards + +Your code should follow our Coding Standards or it will be marked poorly. + +https://syllabus.codeyourfuture.io/guides/code-style-guide diff --git a/HOW-TO-GET-HELP.md b/HOW-TO-GET-HELP.md index 56c70cafd..efa71bc33 100644 --- a/HOW-TO-GET-HELP.md +++ b/HOW-TO-GET-HELP.md @@ -1,37 +1,37 @@ - - -# How To Get Help - -When you get stuck it's important that you ask for help at the right time and in the right way - this means you will be able to solve you problem as quickly as possible! - -## Guide - -Please review our guide on the Syllabus for how to get help - -https://syllabus.codeyourfuture.io/guides/escalation-policy/ - -You should complete all of the steps in the order listed to get help - -## Reporting Issues in Coursework - -Is there a problem with this coursework? -Have you noticed a bug? -Does something not make sense? - -Post in the relevent channel on Slack depending on the module you are completing: - -- Git - `cyf-module-git` -- HTML/CSS - `cyf-module-html-css` -- JavaScript Core 1 - `cyf-module-js1` -- JavaScript Core 2 - `cyf-module-js2` -- JavaScript Core 2 - `cyf-module-js3` -- React - `cyf-module-react` -- Node - `cyf-module-node` -- SQL - `cyf-module-sql` -- MongoDB - `cyf-module-mongodb` - -None of these? Post in #cyf-syllabus. + + +# How To Get Help + +When you get stuck it's important that you ask for help at the right time and in the right way - this means you will be able to solve you problem as quickly as possible! + +## Guide + +Please review our guide on the Syllabus for how to get help + +https://syllabus.codeyourfuture.io/guides/escalation-policy/ + +You should complete all of the steps in the order listed to get help + +## Reporting Issues in Coursework + +Is there a problem with this coursework? +Have you noticed a bug? +Does something not make sense? + +Post in the relevent channel on Slack depending on the module you are completing: + +- Git - `cyf-module-git` +- HTML/CSS - `cyf-module-html-css` +- JavaScript Core 1 - `cyf-module-js1` +- JavaScript Core 2 - `cyf-module-js2` +- JavaScript Core 2 - `cyf-module-js3` +- React - `cyf-module-react` +- Node - `cyf-module-node` +- SQL - `cyf-module-sql` +- MongoDB - `cyf-module-mongodb` + +None of these? Post in #cyf-syllabus. diff --git a/HOW-TO-SUBMIT.md b/HOW-TO-SUBMIT.md index f9430423a..cb8843c72 100644 --- a/HOW-TO-SUBMIT.md +++ b/HOW-TO-SUBMIT.md @@ -1,23 +1,23 @@ - - -# How To Submit Your Coursework - -You should use Git & Github to submit your coursework as a pull request. - -You can use the Github Desktop cheatsheet here to help you do this. - -[Github Desktop Cheatsheet](http://syllabus.codeyourfuture.io/git/cheatsheet) - -You can also use this lesson to help you submit your coursework. - -[Git Lesson](http://syllabus.codeyourfuture.io/git/index) - -## Questions & Help - -Not being able to submit your coursework is not an excuse for not doing it. - -If you cannot submit your coursework you **must** message us on Slack to get help. + + +# How To Submit Your Coursework + +You should use Git & Github to submit your coursework as a pull request. + +You can use the Github Desktop cheatsheet here to help you do this. + +[Github Desktop Cheatsheet](http://syllabus.codeyourfuture.io/git/cheatsheet) + +You can also use this lesson to help you submit your coursework. + +[Git Lesson](http://syllabus.codeyourfuture.io/git/index) + +## Questions & Help + +Not being able to submit your coursework is not an excuse for not doing it. + +If you cannot submit your coursework you **must** message us on Slack to get help. diff --git a/HOW_TO_MARK.md b/HOW_TO_MARK.md index 99bf0f0f7..22b74691b 100644 --- a/HOW_TO_MARK.md +++ b/HOW_TO_MARK.md @@ -1,64 +1,64 @@ - - -_This file is useful for Volunteers only_ - -## 1) Solutions - -### 1.1) Where to find solutions? - -You can find the solution to this coursework in a repository with the same name as this but with `-Solution` after the name. - -For example, for this repo: - -https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1 - -The solutions would be found in: - -https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution - -**If you do not have access to these repositories** then please contact your City Coordinator to get access to our Github Team. - -### 1.2) Using the Solutions Repo - -In these repositories you will find solutions to each weeks coursework. These solutions are example answers and will not be the exact solution that students give. You should use it to inform your feedback of the coursework. - -Additionally, you will find marking guides in these places - -- The `marking` folder - Used to store multiple guides on marking -- `marking.md` file - Used to store notes on common problems we're trying to address -- `solutions.md` - A file used by students for notes on best practice - -## 2) Before You Start - -### 2.1) Feedback Guide - -A guide for marking coursework can be found here. Please read it before you start. - -https://docs.codeyourfuture.io/teams/education/homework-feedback - -### 2.2) Marking Guide - -Here is a useful resources you can direct students to when you see them have common mistakes - -https://syllabus.codeyourfuture.io/guides/marking-guide - -This guide should be used when you see a student making a common mistake so instead of writing out a reply you can send them to the a good resource. - -For example, if the student is leaving in lots of comments out code you could write - -```txt -Great work so far! - -It's best if you remove code that you're not using, you can read more about this here -https://syllabus.codeyourfuture.io/guides/marking-guide#commented-out-code -``` - -### 3.3) Style Guide - -All code at CYF should follow this Style Guide - -https://syllabus.codeyourfuture.io/guides/code-style-guide/ + + +_This file is useful for Volunteers only_ + +## 1) Solutions + +### 1.1) Where to find solutions? + +You can find the solution to this coursework in a repository with the same name as this but with `-Solution` after the name. + +For example, for this repo: + +https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1 + +The solutions would be found in: + +https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution + +**If you do not have access to these repositories** then please contact your City Coordinator to get access to our Github Team. + +### 1.2) Using the Solutions Repo + +In these repositories you will find solutions to each weeks coursework. These solutions are example answers and will not be the exact solution that students give. You should use it to inform your feedback of the coursework. + +Additionally, you will find marking guides in these places + +- The `marking` folder - Used to store multiple guides on marking +- `marking.md` file - Used to store notes on common problems we're trying to address +- `solutions.md` - A file used by students for notes on best practice + +## 2) Before You Start + +### 2.1) Feedback Guide + +A guide for marking coursework can be found here. Please read it before you start. + +https://docs.codeyourfuture.io/teams/education/homework-feedback + +### 2.2) Marking Guide + +Here is a useful resources you can direct students to when you see them have common mistakes + +https://syllabus.codeyourfuture.io/guides/marking-guide + +This guide should be used when you see a student making a common mistake so instead of writing out a reply you can send them to the a good resource. + +For example, if the student is leaving in lots of comments out code you could write + +```txt +Great work so far! + +It's best if you remove code that you're not using, you can read more about this here +https://syllabus.codeyourfuture.io/guides/marking-guide#commented-out-code +``` + +### 3.3) Style Guide + +All code at CYF should follow this Style Guide + +https://syllabus.codeyourfuture.io/guides/code-style-guide/ diff --git a/README.md b/README.md index 5833a402f..e918b3006 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ -# Coursework - -Like learning a musical instrument, programming requires daily practise. - -The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson. - -The `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. - -## Solutions - -The solutions for this coursework can be found here: - -https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution - -This is a **private** repository. Please request access from your Teachers, Buddy or City Coordinator after the start of your next lesson. - -## Instructions for submission - -For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :) - -1. Complete the challenges in each file and save it once you're happy with your changes -2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it. -3. Raise a PR once you're happy with the quality of your code +# Coursework + +Like learning a musical instrument, programming requires daily practise. + +The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson. + +The `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. + +## Solutions + +The solutions for this coursework can be found here: + +https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution + +This is a **private** repository. Please request access from your Teachers, Buddy or City Coordinator after the start of your next lesson. + +## Instructions for submission + +For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :) + +1. Complete the challenges in each file and save it once you're happy with your changes +2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it. +3. Raise a PR once you're happy with the quality of your code diff --git a/exercises/A-setup-ide/README.md b/exercises/A-setup-ide/README.md index de230419b..f1d3eaef1 100644 --- a/exercises/A-setup-ide/README.md +++ b/exercises/A-setup-ide/README.md @@ -1,13 +1,13 @@ -There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read. - -### 1. Install prettier - -- In Visual Studio open the extensions panel (see https://code.visualstudio.com/docs/editor/extension-gallery#_browse-and-install-extensions) -- Search for `Prettier - Code formatter` -- Click install on the top result - -### 2. Enable formatting on save - -- In Visual Studio open the settings file (see https://code.visualstudio.com/docs/getstarted/settings#_creating-user-and-workspace-settings) -- Search for `editor format` -- Set `editor.formatOnSave` and `editor.formatOnPaste` to true +There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read. + +### 1. Install prettier + +- In Visual Studio open the extensions panel (see https://code.visualstudio.com/docs/editor/extension-gallery#_browse-and-install-extensions) +- Search for `Prettier - Code formatter` +- Click install on the top result + +### 2. Enable formatting on save + +- In Visual Studio open the settings file (see https://code.visualstudio.com/docs/getstarted/settings#_creating-user-and-workspace-settings) +- Search for `editor format` +- Set `editor.formatOnSave` and `editor.formatOnPaste` to true diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index 8c704fb43..7efcc60e1 100644 --- a/exercises/B-hello-world/README.md +++ b/exercises/B-hello-world/README.md @@ -1,18 +1,18 @@ -It is programming tradition that the first thing you do in any language is make it output 'Hello world!'. - -We'll do this in JavaScript, using something called `console.log()`. - -Inside of `exercise.js` there's a line of code that will print "Hello world!". - -### 1. Run the program - -- Open a terminal window -- Change directory to this folder (`cd B-hello-world`) -- Run the program using node (`node exercise.js`) - -### 2. Experiment - -- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'. -- Try to console.log() several things at once. -- What happens when you get rid of the quote marks? -- What happens when you console.log() just a number without quotes? +It is programming tradition that the first thing you do in any language is make it output 'Hello world!'. + +We'll do this in JavaScript, using something called `console.log()`. + +Inside of `exercise.js` there's a line of code that will print "Hello world!". + +### 1. Run the program + +- Open a terminal window +- Change directory to this folder (`cd B-hello-world`) +- Run the program using node (`node exercise.js`) + +### 2. Experiment + +- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'. +- Try to console.log() several things at once. +- What happens when you get rid of the quote marks? +- What happens when you console.log() just a number without quotes? diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..ca82f9303 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,5 @@ -console.log("Hello world"); +console.log("Hello world"); +console.log("Hello World, I just started learning JavaScript"); +console.log(2); +console.log(2 + 2); +console.log("11+77"); diff --git a/exercises/C-variables/README.md b/exercises/C-variables/README.md index 40859b3a8..9b0867773 100644 --- a/exercises/C-variables/README.md +++ b/exercises/C-variables/README.md @@ -1,26 +1,26 @@ -When you write code, you'll want to create shortcuts to data values so you can don't have to write out the same value every time. - -We can use _variable_ to create a reference to a value. - -```js -var greeting = "Hello world"; - -console.log(greeting); -``` - -The program above will print "Hello world" to the console. Notice how it uses the value assigned to the variable `greeting`. - -## Exercise - -- Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log) -- Print your `greeting` to the console 3 times - -> Remember: to run this exercise you must change directory to the `C-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../C-variables`. - -## Expected result - -``` -Hello world -Hello world -Hello world -``` +When you write code, you'll want to create shortcuts to data values so you can don't have to write out the same value every time. + +We can use _variable_ to create a reference to a value. + +```js +var greeting = "Hello world"; + +console.log(greeting); +``` + +The program above will print "Hello world" to the console. Notice how it uses the value assigned to the variable `greeting`. + +## Exercise + +- Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log) +- Print your `greeting` to the console 3 times + +> Remember: to run this exercise you must change directory to the `C-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../C-variables`. + +## Expected result + +``` +Hello world +Hello world +Hello world +``` diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..639609e79 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ -// Start by creating a variable `greeting` - -console.log(greeting); +// Start by creating a variable `greeting` +let greeting = "Hello , let's start learning together"; +console.log(greeting); +console.log(greeting); +console.log(greeting); diff --git a/exercises/D-strings/README.md b/exercises/D-strings/README.md index fd0a664ae..3f5887c0c 100644 --- a/exercises/D-strings/README.md +++ b/exercises/D-strings/README.md @@ -1,29 +1,29 @@ -In programming there are different _types of_ data. You've used one data type already: **string**. - -Computers recognise strings as a sequence of characters but to humans, strings are simply lines of text. - -```js -var message = "This is a string"; -``` - -Notice that strings are always wrapped **inside of quote marks**. We do this so that the computer knows when the string starts and ends. - -You can check that the data is a string by using the `typeof` operator: - -```js -var message = "This is a string"; -var messageType = typeof message; - -console.log(messageType); // logs 'string' -``` - -## Exercise - -- Write a program that logs a message and its type - -## Expected result - -``` -This is a string -string -``` +In programming there are different _types of_ data. You've used one data type already: **string**. + +Computers recognise strings as a sequence of characters but to humans, strings are simply lines of text. + +```js +var message = "This is a string"; +``` + +Notice that strings are always wrapped **inside of quote marks**. We do this so that the computer knows when the string starts and ends. + +You can check that the data is a string by using the `typeof` operator: + +```js +var message = "This is a string"; +var messageType = typeof message; + +console.log(messageType); // logs 'string' +``` + +## Exercise + +- Write a program that logs a message and its type + +## Expected result + +``` +This is a string +string +``` diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..03caed490 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ -// Start by creating a variable `message` - -console.log(message); +// Start by creating a variable `message` +let message = "elmira"; +let typeOfMessage = typeof message; + +console.log(message); +console.log(typeOfMessage); diff --git a/exercises/E-strings-concatenation/README.md b/exercises/E-strings-concatenation/README.md index cba54dbca..9427124d9 100644 --- a/exercises/E-strings-concatenation/README.md +++ b/exercises/E-strings-concatenation/README.md @@ -1,20 +1,20 @@ -You can add two strings together using the plus operator (`+`): - -```js -var greetingStart = "Hello, my name is "; -var name = "Daniel"; - -var greeting = greetingStart + name; - -console.log(greeting); // Logs "Hello, my name is Daniel" -``` - -## Exercise - -- Write a program that logs a message with a greeting and your name - -## Expected result - -``` -Hello, my name is Daniel -``` +You can add two strings together using the plus operator (`+`): + +```js +var greetingStart = "Hello, my name is "; +var name = "Daniel"; + +var greeting = greetingStart + name; + +console.log(greeting); // Logs "Hello, my name is Daniel" +``` + +## Exercise + +- Write a program that logs a message with a greeting and your name + +## Expected result + +``` +Hello, my name is Daniel +``` diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..973640c92 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,5 @@ -// Start by creating a variable `message` - -console.log(message); +// Start by creating a variable `message` +let greeting = "Hello,my name is "; +let myName = "Elmira"; +let message = greeting + myName; +console.log(message); diff --git a/exercises/F-strings-methods/README.md b/exercises/F-strings-methods/README.md index fb07ec8ef..1798bdf16 100644 --- a/exercises/F-strings-methods/README.md +++ b/exercises/F-strings-methods/README.md @@ -1,40 +1,40 @@ -You can find out how many characters there are in a string by using the `length` property of a string: - -```js -var name = "Daniel"; -var nameLength = name.length; - -console.log(nameLength); // Logs 6 -``` - -You can also get a modified version of a string by calling _string methods_. Let's try one: - -```js -var name = "Daniel"; -var nameLowerCase = name.toLowerCase(); - -console.log(nameLowerCase); // "daniel" -``` - -You can find out more about string properties and methods by searching for "JavaScript string methods". - -## Exercise 1 - -- Log a message that includes the length of your name - -## Expected result - -``` -My name is Daniel and my name is 6 characters long -``` - -## Exercise 2 - -- Log the same message using the variable, `name` provided -- Use the `.trim` method to remove the extra whitespace - -## Expected result - -``` -My name is Daniel and my name is 6 characters long -``` +You can find out how many characters there are in a string by using the `length` property of a string: + +```js +var name = "Daniel"; +var nameLength = name.length; + +console.log(nameLength); // Logs 6 +``` + +You can also get a modified version of a string by calling _string methods_. Let's try one: + +```js +var name = "Daniel"; +var nameLowerCase = name.toLowerCase(); + +console.log(nameLowerCase); // "daniel" +``` + +You can find out more about string properties and methods by searching for "JavaScript string methods". + +## Exercise 1 + +- Log a message that includes the length of your name + +## Expected result + +``` +My name is Daniel and my name is 6 characters long +``` + +## Exercise 2 + +- Log the same message using the variable, `name` provided +- Use the `.trim` method to remove the extra whitespace + +## Expected result + +``` +My name is Daniel and my name is 6 characters long +``` diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..faba090ec 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,10 @@ -// Start by creating a variable `message` - -console.log(message); +// Start by creating a variable `message` + +let myName = "Elmira"; +let nameLength = myName.length; +let upper = myName.toUpperCase(); + +console.log(upper); +console.log( + `My name is ${myName} and my name is ${nameLength} characters long.` +); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..9190c3416 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,10 @@ -const name = " Daniel "; - -console.log(message); +const myName = " Elmira "; +const trimmedName = myName.trim(); +let trimmedLength = trimmedName.length; +let message = + "My name is" + + myName + + "and my name is" + + trimmedLength + + " characters long."; +console.log(message); diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 76a79dab2..b8c55b588 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -1,29 +1,29 @@ -The next data type we will learn is **number**. - -Unlike strings, numbers do not need to be wrapped in quotes. - -```js -var age = 30; -``` - -You can use mathematical operators to caclulate numbers: - -```js -var sum = 10 + 2; // 12 -var product = 10 * 2; // 20 -var quotient = 10 / 2; // 5 -var difference = 10 - 2; // 8 -``` - -## Exercise - -- Create two variables `numberOfStudents` and `numberOfMentors` -- Log a message that displays the total number of students and mentors - -## Expected result - -``` -Number of students: 15 -Number of mentors: 8 -Total numnber of students and mentors: 23 -``` +The next data type we will learn is **number**. + +Unlike strings, numbers do not need to be wrapped in quotes. + +```js +var age = 30; +``` + +You can use mathematical operators to caclulate numbers: + +```js +var sum = 10 + 2; // 12 +var product = 10 * 2; // 20 +var quotient = 10 / 2; // 5 +var difference = 10 - 2; // 8 +``` + +## Exercise + +- Create two variables `numberOfStudents` and `numberOfMentors` +- Log a message that displays the total number of students and mentors + +## Expected result + +``` +Number of students: 15 +Number of mentors: 8 +Total numnber of students and mentors: 23 +``` diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..e92b70a28 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,7 @@ -// Start by creating a variables `numberOfStudents` and `numberOfMentors` +// Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 31; +let numberOfMentors = 10; +let total = numberOfStudents + numberOfMentors; +// console.log(`Number of strudents: ${numberOfStudents}`); +// console.log(`Number of Mentors : ${numberOfMentors}`); +console.log(`Total number of students and mentors: ${total}`); diff --git a/exercises/I-floats/README.md b/exercises/I-floats/README.md index bbc9e29c2..c257f8bc8 100644 --- a/exercises/I-floats/README.md +++ b/exercises/I-floats/README.md @@ -1,23 +1,23 @@ -Numbers can be integers (whole numbers) or floats (numbers with a decimal). - -```js -var preciseAge = 30.612437; -``` - -Floats can be rounded to the nearest whole number using the `Math.round` function: - -```js -var preciseAge = 30.612437; -var roughAge = Math.round(preciseAge); // 30 -``` - -## Exercise - -- Using the variables provided in the exercise calculate the percentage of mentors and students in the group - -## Expected result - -``` -Percentage students: 65% -Percentage mentors: 35% -``` +Numbers can be integers (whole numbers) or floats (numbers with a decimal). + +```js +var preciseAge = 30.612437; +``` + +Floats can be rounded to the nearest whole number using the `Math.round` function: + +```js +var preciseAge = 30.612437; +var roughAge = Math.round(preciseAge); // 30 +``` + +## Exercise + +- Using the variables provided in the exercise calculate the percentage of mentors and students in the group + +## Expected result + +``` +Percentage students: 65% +Percentage mentors: 35% +``` diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..4bbdeb61c 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,9 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +var numberOfStudents = 15; +var numberOfMentors = 8; +let total = numberOfStudents + numberOfMentors; + +let percentageNumberOfStudents = Math.round((numberOfStudents * 100) / total); +let percentageNumberOfMentors = Math.round((numberOfMentors * 100) / total); + +console.log(`percentage of students : ${percentageNumberOfStudents} %`); +console.log(`percentage of Mentors: ${percentageNumberOfMentors} % `); diff --git a/exercises/J-functions/README.md b/exercises/J-functions/README.md index 22105ca2a..1be896f69 100644 --- a/exercises/J-functions/README.md +++ b/exercises/J-functions/README.md @@ -1,42 +1,42 @@ -Functions are blocks of code that can do a task as many times as you ask it to. They take an input and return an output. - -Here's a function that doubles a number: - -```js -function double(number) { - return number * 2; -} -``` - -To use the function we need to: -a) _call_ it with an input and -b) assign the returned value to a variable - -```js -var result = double(2); - -console.log(result); // 4 -``` - -## Exercise - -- Complete the function in exercise.js so that it halves the input -- Try calling the function more than once with some different numbers - -> Remember to use the return keyword to get a value out of the function - -## Expected result - -``` -6 -``` - -## Exercise 2 - -- Complete the function in exercise2.js so that it triples the input - -## Expected result - -``` -36 -``` +Functions are blocks of code that can do a task as many times as you ask it to. They take an input and return an output. + +Here's a function that doubles a number: + +```js +function double(number) { + return number * 2; +} +``` + +To use the function we need to: +a) _call_ it with an input and +b) assign the returned value to a variable + +```js +var result = double(2); + +console.log(result); // 4 +``` + +## Exercise + +- Complete the function in exercise.js so that it halves the input +- Try calling the function more than once with some different numbers + +> Remember to use the return keyword to get a value out of the function + +## Expected result + +``` +6 +``` + +## Exercise 2 + +- Complete the function in exercise2.js so that it triples the input + +## Expected result + +``` +36 +``` diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..a5494eed6 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,11 @@ -function halve(number) { - // complete the function here -} - -var result = halve(12); - -console.log(result); +function halve(number) { + return number / 2; +} + +var result = halve(12); +var result1 = halve(100); +var result2 = halve(50); + +console.log(result); +console.log(result1); +console.log(result2); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..7c7aabc05 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,7 @@ -function triple(number) { - // complete function here -} - -var result = triple(12); - -console.log(result); +function triple(number) { + return number * 3; +} + +var result = triple(12); + +console.log(result); diff --git a/exercises/K-functions-parameters/README.md b/exercises/K-functions-parameters/README.md index 1614e221b..b7ff14b7c 100644 --- a/exercises/K-functions-parameters/README.md +++ b/exercises/K-functions-parameters/README.md @@ -1,70 +1,70 @@ -The input given to a function is called a **parameter**. - -A function can take more than one parameter: - -```js -function add(a, b) { - return a + b; -} -``` - -When you write a function (sometimes called _declaring a function_) you assign names to the parameters inside of the parentheses (`()`). Parameters can be called anything. - -This function is exactly the same as the on above: - -```js -function add(num1, num2) { - return num1 + num2; -} -``` - -## Exercise - -- Write a function that multiplies two numbers together - -## Expected result - -``` -12 -``` - -## Exercise 2 - -- From scratch, write a function that divides two numbers - -## Expected result - -``` -0.75 -``` - -## Exercise 3 - -- Write a function that takes a name (a string) and returns a greeting - -## Expected result - -``` -Hello, my name is Daniel -``` - -## Exercise 4 - -- Write a function that adds two numbers together -- Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum` - -## Expected result - -``` -137 -``` - -## Exercise 5 - -- Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) - -## Expected result - -``` -Hello, my name is Daniel and I'm 30 years old -``` +The input given to a function is called a **parameter**. + +A function can take more than one parameter: + +```js +function add(a, b) { + return a + b; +} +``` + +When you write a function (sometimes called _declaring a function_) you assign names to the parameters inside of the parentheses (`()`). Parameters can be called anything. + +This function is exactly the same as the on above: + +```js +function add(num1, num2) { + return num1 + num2; +} +``` + +## Exercise + +- Write a function that multiplies two numbers together + +## Expected result + +``` +12 +``` + +## Exercise 2 + +- From scratch, write a function that divides two numbers + +## Expected result + +``` +0.75 +``` + +## Exercise 3 + +- Write a function that takes a name (a string) and returns a greeting + +## Expected result + +``` +Hello, my name is Daniel +``` + +## Exercise 4 + +- Write a function that adds two numbers together +- Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum` + +## Expected result + +``` +137 +``` + +## Exercise 5 + +- Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) + +## Expected result + +``` +Hello, my name is Daniel and I'm 30 years old +``` diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..9fbb59d95 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,9 @@ -// Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it -} - -// Assign the result of calling the function the variable `result` -var result = multiply(3, 4); - -console.log(result); +// Complete the function so that it takes input parameters +function multiply(num1, num2) { + return num1 * num2; +} + +// Assign the result of calling the function the variable `result` +var result = multiply(3, 4); + +console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..0e637603f 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ -// Declare your function first - -var result = divide(3, 4); - -console.log(result); +function divide(num1,num2){ + return num1 / num2 ; +} + +var result = divide(3, 4); + +console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..1ab1fc8ee 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ -// Write your function here - -var greeting = createGreeting("Daniel"); - -console.log(greeting); +function createGreeting(myName) { + return `Hello,my name is ${myName}`; +} + +var greeting = createGreeting("Daniel"); + +console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..58dddf0be 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ -// Declare your function first - -// Call the function and assign to a variable `sum` - -console.log(sum); +function add(num1, num2) { + return num1 + num2; +} + +let sum = add(13, 124); + +console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..b39caa868 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ -// Declare your function here - -const greeting = createLongGreeting("Daniel", 30); - -console.log(greeting); +function createLongGreeting(myName,age){ + return `Hello,my name is ${myName} and I'm ${age} years old`; +} + +const greeting = createLongGreeting("Daniel", 30); + +console.log(greeting); diff --git a/exercises/L-functions-nested/README.md b/exercises/L-functions-nested/README.md index 1c4ae9c8a..cd606cb99 100644 --- a/exercises/L-functions-nested/README.md +++ b/exercises/L-functions-nested/README.md @@ -1,34 +1,34 @@ -Functions are very powerful. - -- You can write more than one line of code inside of functions. -- You can use variables inside of functions. -- You can call other functions inside of functions! - -```js -function getAgeInDays(age) { - return age * 365; -} - -function createCreeting(name, age) { - var ageInDays = getAgeInDays(age); - var message = - "My Name is " + name + " and I was born over " + ageInDays + " days ago!"; - return message; -} -``` - -## Exercise 1 - -- In `exercise.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one. -- Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting. -- Log each greeting to the console. - -## Expected result - -``` -HELLO DANIEL -HELLO IRINA -HELLO MIMI -HELLO ROB -HELLO YOHANNES -``` +Functions are very powerful. + +- You can write more than one line of code inside of functions. +- You can use variables inside of functions. +- You can call other functions inside of functions! + +```js +function getAgeInDays(age) { + return age * 365; +} + +function createCreeting(name, age) { + var ageInDays = getAgeInDays(age); + var message = + "My Name is " + name + " and I was born over " + ageInDays + " days ago!"; + return message; +} +``` + +## Exercise 1 + +- In `exercise.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one. +- Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting. +- Log each greeting to the console. + +## Expected result + +``` +HELLO DANIEL +HELLO IRINA +HELLO MIMI +HELLO ROB +HELLO YOHANNES +``` diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..94cbb51aa 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,19 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +var mentor1 = "Daniel"; +var mentor2 = "Irina"; +var mentor3 = "Mimi"; +var mentor4 = "Rob"; +var mentor5 = "Yohannes"; + +function upperCase(mentorName) { + return mentorName.toUpperCase(); +} + +function shoutyGreeting(mentorName) { + return `HELLO ${upperCase(mentorName)}`; +} + +console.log(shoutyGreeting(mentor1)); +console.log(shoutyGreeting(mentor2)); +console.log(shoutyGreeting(mentor3)); +console.log(shoutyGreeting(mentor4)); +console.log(shoutyGreeting(mentor5)); diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index d82e59480..80ff20010 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -1,41 +1,47 @@ -/* - CURRENCY CONVERSION - =================== - The business is breaking out into a new market and need to convert prices to USD - Write a function that converts a price to USD (exchange rate is 1.4 $ to £) -*/ - -function convertToUSD() {} - -/* - CURRENCY CONVERSION - =================== - The business is now breaking into the Brazilian market - Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) - They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. -*/ - -function convertToBRL() {} - -/* ======= TESTS - DO NOT MODIFY ===== -There are some Tests in this file that will help you work out if your code is working. - -To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("convertToUSD function works for £32", () => { - expect(convertToUSD(32)).toEqual(44.8); -}); - -test("convertToUSD function works for £50", () => { - expect(convertToUSD(50)).toEqual(70); -}); - -test("convertToBRL function works for £30", () => { - expect(convertToBRL(30)).toEqual(169.29); -}); - -test("convertToBRL function works for £1.50", () => { - expect(convertToBRL(1.5)).toEqual(8.46); -}); +/* + CURRENCY CONVERSION + =================== + The business is breaking out into a new market and need to convert prices to USD + Write a function that converts a price to USD (exchange rate is 1.4 $ to £) +*/ + +function convertToUSD(price) { + return price * 1.4; +} + +/* + CURRENCY CONVERSION + =================== + The business is now breaking into the Brazilian market + Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) + They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. +*/ + +function convertToBRL(price) { + const convertedPrice = 5.7 * ((price * 99) / 100); + // The parseFloat() function parses an argument (converting it to a string first if needed) and returns a floating point number. + return parseFloat(convertedPrice.toFixed(2)); +} + +/* ======= TESTS - DO NOT MODIFY ===== +There are some Tests in this file that will help you work out if your code is working. + +To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("convertToUSD function works for £32", () => { + expect(convertToUSD(32)).toEqual(44.8); +}); + +test("convertToUSD function works for £50", () => { + expect(convertToUSD(50)).toEqual(70); +}); + +test("convertToBRL function works for £30", () => { + expect(convertToBRL(30)).toEqual(169.29); +}); + +test("convertToBRL function works for £1.50", () => { + expect(convertToBRL(1.5)).toEqual(8.46); +}); diff --git a/extra/2-piping.js b/extra/2-piping.js index 9c8ebc76a..fa1bcf062 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -1,73 +1,76 @@ -/* - PIPING FUNCTIONS - ================ - 1. Write 3 functions: - - one that adds 2 numbers together - - one that multiplies 2 numbers together - - one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20) - - 2. Using the variable startingValue as input, perform the following operations using your functions all - on one line (assign the result to the variable badCode): - - add 10 to startingValue - - multiply the result by 2 - - format it - - 3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign - the final result to the variable goodCode -*/ - -function add() { - -} - -function multiply() { - -} - -function format() { - -} - -const startingValue = 2; - -// Why can this code be seen as bad practice? Comment your answer. -let badCode = - -/* BETTER PRACTICE */ - -let goodCode = - -/* ======= TESTS - DO NOT MODIFY ===== -There are some Tests in this file that will help you work out if your code is working. - -To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 2-piping` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("add function - case 1 works", () => { - expect(add(1, 3)).toEqual(4); -}); - -test("add function - case 2 works", () => { - expect(add(2.4, 5)).toEqual(7.4); -}); - -test("multiply function works", () => { - expect(multiply(2, 3)).toEqual(6); -}); - -test("format function works for whole number", () => { - expect(format(16)).toEqual("£16"); -}); - -test("format function works for decimal number", () => { - expect(format(10.1)).toEqual("£10.1"); -}); - -test("badCode variable correctly assigned", () => { - expect(badCode).toEqual("£24"); -}); - -test("goodCode variable correctly assigned", () => { - expect(goodCode).toEqual("£24"); -}); +/* + PIPING FUNCTIONS + ================ + 1. Write 3 functions: + - one that adds 2 numbers together + - one that multiplies 2 numbers together + - one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20) + + 2. Using the variable startingValue as input, perform the following operations using your functions all + on one line (assign the result to the variable badCode): + - add 10 to startingValue + - multiply the result by 2 + - format it + + 3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign + the final result to the variable goodCode +*/ + +function add(num1, num2) { + return num1 + num2; +} + +function multiply(num1, num2) { + return num1 * num2; +} + +function format(price) { + return `£${price}`; +} + +const startingValue = 2; + +// Why can this code be seen as bad practice? Comment your answer. +// beacuse it is not easy to underestand whats happening in that nested functions. +let badCode = format(multiply(add(startingValue, 10), 2)); + +/* BETTER PRACTICE */ + +let addedNumbers = add(startingValue, 10); +let multiplyedNumbers = multiply(addedNumbers, 2); +let goodCode = format(multiplyedNumbers); + +/* ======= TESTS - DO NOT MODIFY ===== +There are some Tests in this file that will help you work out if your code is working. + +To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 2-piping` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("add function - case 1 works", () => { + expect(add(1, 3)).toEqual(4); +}); + +test("add function - case 2 works", () => { + expect(add(2.4, 5)).toEqual(7.4); +}); + +test("multiply function works", () => { + expect(multiply(2, 3)).toEqual(6); +}); + +test("format function works for whole number", () => { + expect(format(16)).toEqual("£16"); +}); + +test("format function works for decimal number", () => { + expect(format(10.1)).toEqual("£10.1"); +}); + +test("badCode variable correctly assigned", () => { + expect(badCode).toEqual("£24"); +}); + +test("goodCode variable correctly assigned", () => { + expect(goodCode).toEqual("£24"); +}); diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index f3adbefa5..250f54687 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -1,118 +1,169 @@ -/** - - Let's peer into the future using a Magic 8 Ball! - https://en.wikipedia.org/wiki/Magic_8-Ball - - There are a few steps to being able view the future though: - * Ask a question - * Shake the ball - * Get an answer - * Decide if it's positive or negative - - The question can be anything, but the answers are fixed, - and have different levels of positivity or negativity. - - Below are the possible answers: - - ## Very positive - It is certain. - It is decidedly so. - Without a doubt. - Yes - definitely. - You may rely on it. - - ## Positive - As I see it, yes. - Most likely. - Outlook good. - Yes. - Signs point to yes. - - ## Negative - Reply hazy, try again. - Ask again later. - Better not tell you now. - Cannot predict now. - Concentrate and ask again. - - ## Very negative - Don't count on it. - My reply is no. - My sources say no. - Outlook not so good. - Very doubtful. -*/ - -// This should log "The ball has shaken!" -// and return the answer. -function shakeBall() { - //Write your code in here -} - -/* - This function should say whether the answer it is given is - - very positive - - positive - - negative - - very negative - - This function should expect to be called with any value which was returned by the shakeBall function. -*/ -function checkAnswer(answer) { - //Write your code in here -} - -/* -================================== -======= TESTS - DO NOT MODIFY ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 3-magic-8-ball` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -================================== -*/ - -test("whole magic 8 ball sequence", () => { - const consoleLogSpy = jest.spyOn(global.console, "log"); - const answer = shakeBall(); - - expect(typeof answer).toEqual("string"); - - expect(consoleLogSpy).toHaveBeenCalledTimes(1); - expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!"); - - expect(checkAnswer(answer)).toBeOneOf([ - "very positive", - "positive", - "negative", - "very negative", - ]); -}); - -test("magic 8 ball returns different values each time", () => { - const seenAnswers = new Set(); - for (let i = 0; i < 10; ++i) { - seenAnswers.add(shakeBall()); - } - if (seenAnswers.size < 2) { - throw Error( - "Expected to get different random answers each time shakeBall was called, but always got the same one" - ); - } - - let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer)); - if (seenPositivities.size < 2) { - throw Error( - "Expected to random answers with different positivities each time shakeBall was called, but always got the same one" - ); - } -}); - -test("checkAnswer works for `It is decidedly so.`", () => { - expect(checkAnswer("It is decidedly so.")).toEqual("very positive"); -}); - -test("checkAnswer works for `My reply is no.`", () => { - expect(checkAnswer("My reply is no.")).toEqual("very negative"); -}); +/** + + Let's peer into the future using a Magic 8 Ball! + https://en.wikipedia.org/wiki/Magic_8-Ball + + There are a few steps to being able view the future though: + * Ask a question + * Shake the ball + * Get an answer + * Decide if it's positive or negative + + The question can be anything, but the answers are fixed, + and have different levels of positivity or negativity. + + Below are the possible answers: + + ## Very positive + It is certain. + It is decidedly so. + Without a doubt. + Yes - definitely. + You may rely on it. + + ## Positive + As I see it, yes. + Most likely. + Outlook good. + Yes. + Signs point to yes. + + ## Negative + Reply hazy, try again. + Ask again later. + Better not tell you now. + Cannot predict now. + Concentrate and ask again. + + ## Very negative + Don't count on it. + My reply is no. + My sources say no. + Outlook not so good. + Very doubtful. +*/ +// assume answer is an object which contain a few possible answers which they are an array +const answersObj = { + "very positive": [ + "It is certain", + "It is decidedly so.", + "Without a doubt.", + "Yes - definitely.", + "You may rely on it.", + ], + + positive: [ + "As I see it, yes.", + "Most likely.", + "Outlook good.", + "Yes.", + "Signs point to yes.", + ], + + negative: [ + "Reply hazy, try again.", + "Ask again later.", + "Better not tell you now.", + "Cannot predict now.", + "Concentrate and ask again.", + ], + + "very negative": [ + "Don't count on it.", + "My reply is no.", + "My sources say no.", + "Outlook not so good.", + "Very doubtful.", + ], +}; +// This should log "The ball has shaken!" +// and return the answer. +function shakeBall() { + console.log("The ball has shaken!"); + // i concatinate all the arrays into one. in order to reach any of the items easily. so with concat () method , i define an empty array then concatinate all other arrays in that empty one. + const answers = [].concat( + answersObj["very positive"], + answersObj["positive"], + answersObj["negative"], + answersObj["very negative"] + ); + // selects a random index of the answers list through length of an array + // Math.floor remove decimal numbers. make it as integer.also possible to use parseInt() . + const selectedAnswers = answers[Math.floor(Math.random() * answers.length)]; + return selectedAnswers; +} + +/* + This function should say whether the answer it is given is + - very positive + - positive + - negative + - very negative + + This function should expect to be called with any value which was returned by the shakeBall function. +*/ +function checkAnswer(answer) { + let answerCategory = undefined; + Object.keys(answersObj).forEach(function (key) { + if (answersObj[key].includes(answer)) { + answerCategory = key; + } + }); + return answerCategory; +} + +/* +================================== +======= TESTS - DO NOT MODIFY ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 3-magic-8-ball` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +================================== +*/ + +test("whole magic 8 ball sequence", () => { + const consoleLogSpy = jest.spyOn(global.console, "log"); + const answer = shakeBall(); + expect(typeof answer).toEqual("string"); + + expect(consoleLogSpy).toHaveBeenCalledTimes(1); + expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!"); + + expect(checkAnswer(answer)).toBeOneOf([ + "very positive", + "positive", + "negative", + "very negative", + ]); +}); + +test("magic 8 ball returns different values each time", () => { + const seenAnswers = new Set(); + for (let i = 0; i < 10; ++i) { + seenAnswers.add(shakeBall()); + } + if (seenAnswers.size < 2) { + throw Error( + "Expected to get different random answers each time shakeBall was called, but always got the same one" + ); + } + + let seenPositivities = new Set( + Array.from(seenAnswers.values()).map(checkAnswer) + ); + if (seenPositivities.size < 2) { + throw Error( + "Expected to random answers with different positivities each time shakeBall was called, but always got the same one" + ); + } +}); + +test("checkAnswer works for `It is decidedly so.`", () => { + expect(checkAnswer("It is decidedly so.")).toEqual("very positive"); +}); + +test("checkAnswer works for `My reply is no.`", () => { + expect(checkAnswer("My reply is no.")).toEqual("very negative"); +}); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..76606f2b5 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,40 +1,40 @@ -// There are syntax errors in this code - can you fix it to pass the tests? - -function addNumbers(a b c) { - return a + b + c; -} - -function introduceMe(name, age) - return "Hello, my name is " + name "and I am " age + "years old"; - -function getTotal(a, b) { - total = a ++ b; - - return "The total is total"; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 1-syntax-errors` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) - -=================================================== -*/ - -test("addNumbers adds numbers correctly", () => { - expect(addNumbers(3, 4, 6)).toEqual(13); -}); - -test("introduceMe function returns the correct string", () => { - expect(introduceMe("Sonjide", 27)).toEqual( - "Hello, my name is Sonjide and I am 27 years old" - ); -}); - -test("getTotal returns a string describing the total", () => { - expect(getTotal(23, 5)).toEqual("The total is 28"); -}); +// There are syntax errors in this code - can you fix it to pass the tests? + +function addNumbers(a, b, c) { + return a + b + c; +} + +function introduceMe(name, age) { + return "Hello, my name is " + name + " and I am " + age + " years old"; +} +function getTotal(a, b) { + total = a + b; + + return `The total is ${total}`; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 1-syntax-errors` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) + +=================================================== +*/ + +test("addNumbers adds numbers correctly", () => { + expect(addNumbers(3, 4, 6)).toEqual(13); +}); + +test("introduceMe function returns the correct string", () => { + expect(introduceMe("Sonjide", 27)).toEqual( + "Hello, my name is Sonjide and I am 27 years old" + ); +}); + +test("getTotal returns a string describing the total", () => { + expect(getTotal(23, 5)).toEqual("The total is 28"); +}); diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..c9cdb5657 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,51 +1,50 @@ -// The syntax for this function is valid but it has an error, find it and fix it. - -function trimWord(word) { - return wordtrim(); -} - -function getStringLength(word) { - return "word".length(); -} - -function multiply(a, b, c) { - a * b * c; - return; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 2-logic-error` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -=================================================== -*/ - -test("trimWord trims leading and trailing whitespace", () => { - expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture"); -}); - -test("trimWord doesn't remove whitespace in the middle of the string", () => { - expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( - "CodeYourFuture teaches coding" - ); -}); - -test("getStringLength returns the length of a word", () => { - expect(getStringLength("Turtles")).toEqual(7); -}); - -test("getStringLength returns the length of a sentence", () => { - expect(getStringLength("A wild sentence appeared!")).toEqual(25); -}); - -test("multiply multiplies numbers", () => { - expect(multiply(2, 3, 6)).toEqual(36); -}); - -test("multiply multiplies different numbers", () => { - expect(multiply(2, 3, 4)).toEqual(24); -}); +// The syntax for this function is valid but it has an error, find it and fix it. + +function trimWord(word) { + return word.trim(); +} + +function getStringLength(word) { + return word.length; +} + +function multiply(a, b, c) { + return a * b * c; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 2-logic-error` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +=================================================== +*/ + +test("trimWord trims leading and trailing whitespace", () => { + expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture"); +}); + +test("trimWord doesn't remove whitespace in the middle of the string", () => { + expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( + "CodeYourFuture teaches coding" + ); +}); + +test("getStringLength returns the length of a word", () => { + expect(getStringLength("Turtles")).toEqual(7); +}); + +test("getStringLength returns the length of a sentence", () => { + expect(getStringLength("A wild sentence appeared!")).toEqual(25); +}); + +test("multiply multiplies numbers", () => { + expect(multiply(2, 3, 6)).toEqual(36); +}); + +test("multiply multiplies different numbers", () => { + expect(multiply(2, 3, 4)).toEqual(24); +}); diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..22bb3b392 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,37 +1,38 @@ -// Add comments to explain what this function does. You're meant to use Google! -function getRandomNumber() { - return Math.random() * 10; -} - -// Add comments to explain what this function does. You're meant to use Google! -function combine2Words(word1, word2) { - return word1.concat(word2); -} - -function concatenate(firstWord, secondWord, thirdWord) { - // Write the body of this function to concatenate three words together. - // Look at the test case below to understand what this function is expected to return. -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 3-function-output` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -================================== -*/ - -test("concatenate example #1", () => { - expect(concatenate("code", "your", "future")).toEqual("code your future"); -}); - -test("concatenate example #2", () => { - expect(concatenate("I", "like", "pizza")).toEqual("I like pizza"); -}); - -test("concatenate doesn't only accept strings", () => { - expect(concatenate("I", "am", 13)).toEqual("I am 13"); -}); +// Add comments to explain what this function does. You're meant to use Google! +// Math.random() always returns a number lower than 1. (between 0,1). this function every time return a random number between 0 to less than 10. +function getRandomNumber() { + return Math.random() * 10; +} + +// Add comments to explain what this function does. You're meant to use Google! +// concat() method joins two or more strings. +function combine2Words(word1, word2) { + return word1.concat(word2); +} + +function concatenate(firstWord, secondWord, thirdWord) { + return firstWord.concat(" ", secondWord, " ", thirdWord); +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 3-function-output` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +================================== +*/ + +test("concatenate example #1", () => { + expect(concatenate("code", "your", "future")).toEqual("code your future"); +}); + +test("concatenate example #2", () => { + expect(concatenate("I", "like", "pizza")).toEqual("I like pizza"); +}); + +test("concatenate doesn't only accept strings", () => { + expect(concatenate("I", "am", 13)).toEqual("I am 13"); +}); diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..335242787 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -1,55 +1,63 @@ -/* - SALES TAX - ========= - A business requires a program that calculates how much the price of a product is including sales tax - Sales tax is 20% of the price of the product. -*/ - -function calculateSalesTax() {} - -/* - CURRENCY FORMATTING - =================== - The business has informed you that prices must have 2 decimal places - They must also start with the currency symbol - Write a function that adds tax to a number, and then transforms the total into the format £0.00 - - Remember that the prices must include the sales tax (hint: you already wrote a function for this!) -*/ - -function addTaxAndFormatCurrency() {} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 4-tax` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -=================================================== -*/ - -test("calculateSalesTax for £15", () => { - expect(calculateSalesTax(15)).toEqual(18); -}); - -test("calculateSalesTax for £17.50", () => { - expect(calculateSalesTax(17.5)).toEqual(21); -}); - -test("calculateSalesTax for £34", () => { - expect(calculateSalesTax(34)).toEqual(40.8); -}); - -test("addTaxAndFormatCurrency for £15", () => { - expect(addTaxAndFormatCurrency(15)).toEqual("£18.00"); -}); - -test("addTaxAndFormatCurrency for £17.50", () => { - expect(addTaxAndFormatCurrency(17.5)).toEqual("£21.00"); -}); - -test("addTaxAndFormatCurrency for £34", () => { - expect(addTaxAndFormatCurrency(34)).toEqual("£40.80"); -}); +/* + SALES TAX + ========= + A business requires a program that calculates how much the price of a product is including sales tax + Sales tax is 20% of the price of the product. +*/ + +function calculateSalesTax(price) { + let tax = (20 * price) / 100 + price; + return tax; +} + +/* + CURRENCY FORMATTING + =================== + The business has informed you that prices must have 2 decimal places + They must also start with the currency symbol + Write a function that adds tax to a number, and then transforms the total into the format £0.00 + + Remember that the prices must include the sales tax (hint: you already wrote a function for this!) +*/ + +function addTaxAndFormatCurrency(price) { + const taxIncludedPrice = calculateSalesTax(price); + const priceWithTwoDecimal = taxIncludedPrice.toFixed(2); + const localPrice = `£${priceWithTwoDecimal}`; + return localPrice; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 4-tax` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +=================================================== +*/ + +test("calculateSalesTax for £15", () => { + expect(calculateSalesTax(15)).toEqual(18); +}); + +test("calculateSalesTax for £17.50", () => { + expect(calculateSalesTax(17.5)).toEqual(21); +}); + +test("calculateSalesTax for £34", () => { + expect(calculateSalesTax(34)).toEqual(40.8); +}); + +test("addTaxAndFormatCurrency for £15", () => { + expect(addTaxAndFormatCurrency(15)).toEqual("£18.00"); +}); + +test("addTaxAndFormatCurrency for £17.50", () => { + expect(addTaxAndFormatCurrency(17.5)).toEqual("£21.00"); +}); + +test("addTaxAndFormatCurrency for £34", () => { + expect(addTaxAndFormatCurrency(34)).toEqual("£40.80"); +}); diff --git a/package.json b/package.json index f89e73b85..7ad600bb8 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,27 @@ -{ - "name": "javascript-core-1-coursework-week1", - "version": "1.0.0", - "description": "Exercises for JS1 Week 1", - "license": "CC-BY-SA-4.0", - "scripts": { - "test": "jest --testRegex='mandatory[/\\\\].*\\.js$'", - "extra-tests": "jest --testRegex='extra[/\\\\].*\\.js$'" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1.git" - }, - "bugs": { - "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" - }, - "jest": { - "setupFilesAfterEnv": [ - "jest-extended" - ] - }, - "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme", - "devDependencies": { - "jest": "^26.6.3", - "jest-extended": "^0.11.5" - } -} +{ + "name": "javascript-core-1-coursework-week1", + "version": "1.0.0", + "description": "Exercises for JS1 Week 1", + "license": "CC-BY-SA-4.0", + "scripts": { + "test": "jest --testRegex='mandatory[/\\\\].*\\.js$'", + "extra-tests": "jest --testRegex='extra[/\\\\].*\\.js$'" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1.git" + }, + "bugs": { + "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" + }, + "jest": { + "setupFilesAfterEnv": [ + "jest-extended" + ] + }, + "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme", + "devDependencies": { + "jest": "^26.6.3", + "jest-extended": "^0.11.5" + } +}